尝试update-database
执行迁移步骤时出现以下错误(打开包管理器控制台窗口并输入“update-database”命令)
System.Data.Entity.Validation.DbEntityValidationException:一个或多个实体的验证失败。有关更多详细信息,请参阅“EntityValidationErrors”属性。
我在Movie
课堂上添加新字段
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; }
}
并且新字段的添加迁移类包含这个 up 和 down 方法
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");
}
当我删除这两个字段并更新数据库时,种子方法成功运行
有什么建议么?
谢谢你。