除其他外,我的模型还包含两个属性,这些属性在初始创建和迁移后添加到模型类中。
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
and 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 启用自动迁移。
可能是什么原因造成的?