【发布时间】:2016-10-11 04:42:15
【问题描述】:
除其他外,我的模型包含两个属性,这些属性在初始创建和迁移后添加到模型类中。
public sealed class SomeModel
{
... other properties, which are fine.
public int PropertyOne { get; set; }
public int PropertyTwo { get; set; }
}
我最近的迁移包含:
public override void Up()
{
... other table being created.
AddColumn("dbo.SomeModel", "PropertyOne", c => c.Int(nullable: false));
AddColumn("dbo.SomeModel", "PropertyTwo", c => c.Int(nullable: false));
}
目标数据库包含PropertyOne 和PropertyTwo 列,__MigrationHistory 表包含创建表的迁移和添加列的迁移的条目。
当我运行Add-Migration 进行其他更改时,它还再次包含这两个属性:
public override void Up()
{
... other changes.
AddColumn("dbo.SomeModel", "PropertyOne", c => c.Int(nullable: false));
AddColumn("dbo.SomeModel", "PropertyTwo", c => c.Int(nullable: false));
}
这可能是什么原因造成的?我还注意到,如果我恢复所有模型更改并尝试Update-Database(应该什么都不做),我会收到错误:
无法更新数据库以匹配当前模型,因为有 挂起的更改和自动迁移被禁用。要么写 待定模型更改为基于代码的迁移或启用自动 移民。将 DbMigrationsConfiguration.AutomaticMigrationsEnabled 设置为 true 启用自动迁移。
可能是什么原因造成的?
【问题讨论】:
标签: .net entity-framework ef-code-first entity-framework-migrations