2

I get the following error when I'm trying to update-database in the migration steps (open the Package Manager Console window and enter "update-database" command)

System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

I add new field in the Movie class

public class Movie
{
        public int ID { get; set; }
        [Required]
        [DisplayName("Name")]
        public string MovieName { get; set; }
        [Required]
        [DisplayName("Type")]
        public string MovieType { get; set; }
        [DisplayName("Year")]
        public int MovieProductionYear { get; set; }
        [Range(1, 5)]
        [DisplayName("Priority")]
        public int priority { get; set; }
        [DisplayName("NoOfWatches")]
        public int NumberOfWatches { get; set; }
        [DisplayName("isWatched")]
        public bool isWatched { get; set; }
        [Range(1, 10)]
        [DisplayName("IMDB")]
        public int IMDBRating { get; set; }
        [DisplayName("Available")]
        public bool Availability { get; set; }
        [StringLength(50)]
        [DisplayName("Comments")]
        public string Comments { get; set; }
        [DisplayName("Actor")]
        public string Actor { get; set; }
        [DataType(DataType.Date)]
        public DateTime ReleasedDate { get; set; }
    }

and the add migration class for the new fields contains this up and down methods

public override void Up()
{
    AddColumn("dbo.Movies", "NumberOfWatches", c => c.Int(nullable: false));
    AddColumn("dbo.Movies", "ReleasedDate", c => c.DateTime(nullable: false));
}

public override void Down()
{
    DropColumn("dbo.Movies", "ReleasedDate");
    DropColumn("dbo.Movies", "NumberOfWatches");
}

When I remove the two fields and update the database the seed method runs successfully

Any suggestions?

Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Amr Ramadan
  • 1,259
  • 5
  • 18
  • 29
  • If you use **Entity Framework** you can have a look at my answer on [Solution for “Validation failed for one or more entities. See 'EntityValidationErrors' property for more details](http://stackoverflow.com/questions/21486072/solution-for-validation-failed-for-one-or-more-entities-see-entityvalidatione/29031857#29031857). Hope this helps... – Murat Yıldız Jan 26 '16 at 23:14

1 Answers1

1

Does the seed method contain a value of zero for NumberofWatches? This is a non-nullable int and you will need to provide a zero (or other integer value) at the seed. Similarly ReleaseDate will need a date value on each movie seed objects since it is also non-nullable.

Judo
  • 5,167
  • 3
  • 24
  • 34
  • Are you adding nullable values? Ie a Nullable int and a Nullable DateTime? Adding the standard non-nullable values will still cause an error to be thrown. – Judo Nov 25 '12 at 10:32