Entity Framework 7 一直在创建相同的迁移,并且没有获取任何模型更改

Entity Framework 7 keeps creating the same migration, and isn't picking up any model changes

我的 EF7 命令:dnx ef migrations add NAME_HERE 每次我 运行 时都会不断地创建完全相同的迁移。即使我使用 dnx ef database update 更新数据库并观察推送到数据库的更改,我也会添加一个新的迁移并再次创建相同的东西。

另请注意,迁移未获取我的模型更改。我从模型中删除的属性未显示在迁移中。

它不断生成的代码是:

    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropForeignKey(name: "FK_FooEvent_Organizer_OrganizerForeignKey", table: "FooEvent");
        migrationBuilder.AddForeignKey(
            name: "FK_FooEvent_Organizer_OrganizerForeignKey",
            table: "FooEvent",
            column: "OrganizerForeignKey",
            principalTable: "Organizer",
            principalColumn: "Id",
            onDelete: ReferentialAction.Cascade);
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropForeignKey(name: "FK_FooEvent_Organizer_OrganizerForeignKey", table: "FooEvent");
        migrationBuilder.AddForeignKey(
            name: "FK_FooEvent_Organizer_OrganizerForeignKey",
            table: "FooEvent",
            column: "OrganizerForeignKey",
            principalTable: "Organizer",
            principalColumn: "Id",
            onDelete: ReferentialAction.Restrict);
    }
}

我的 DbContext 看起来像这样:

public DbSet<FaroEvent> FaroEvents { get; set; }
public DbSet<Organizer> Organizers { get; set; }

我的模型与迁移相关的属性是:

public int OrganizerForeignKey { get; set; }

[Required, ForeignKey("OrganizerForeignKey")]
public Organizer Organizer { get; set; }

外键问题已在 rc2 中修复:https://github.com/aspnet/EntityFramework/issues/3751

如果迁移未获取模型更改,我建议您查看迁移[context_name]ContextModelSnapshot.cs 文件以查看 EF 认为您的模型是什么。您可以尝试手动修复快照文件或删除 ContextModelSnapshot.cs 文件和所有迁移并重新开始初始迁移。