实体框架代码首次迁移并不总是运行良好

时间:2017-10-27 11:59:58

标签: entity-framework migration code-first

我为我最近对我的模型所做的更改创建了一个迁移,该迁移产生了以下脚本,

        DropIndex("dbo.InboundActions", new[] { "ReferredFrom_Id1" });
        DropIndex("dbo.InboundCopyActionLogs", new[] { "InboundReferToEmployee_Id" });
        DropIndex("dbo.InboundCopyActions", new[] { "ReferredFrom_Id1" });
        DropColumn("dbo.InboundActions", "ReferredFrom_Id");
        DropColumn("dbo.InboundCopyActions", "ReferredFrom_Id");
        RenameColumn(table: "dbo.InboundCopyActionLogs", name: "InboundReferToDivision_Id", newName: "InboundRefer_Id");
        RenameColumn(table: "dbo.InboundCopyActions", name: "ReferredFrom_Id1", newName: "ReferredFrom_Id");
        RenameColumn(table: "dbo.InboundCopyActionLogs", name: "InboundReferToEmployee_Id", newName: "InboundRefer_Id");
        RenameColumn(table: "dbo.InboundActions", name: "ReferredFrom_Id1", newName: "ReferredFrom_Id");
        RenameIndex(table: "dbo.InboundCopyActionLogs", name: "IX_InboundReferToDivision_Id", newName: "IX_InboundRefer_Id");

现在,当我尝试更新数据库时,我收到以下错误,

  

索引'IX_ReferredFrom_Id'依赖于列'ReferredFrom_Id'。   对象'FK_dbo.InboundActions_dbo.Divisions_ReferredFrom_Id'依赖于列'ReferredFrom_Id'。   ALTER TABLE DROP COLUMN ReferredFrom_Id失败,因为一个或多个对象访问此列。

这不是我第一次发现这种迁移错误,这迫使我放弃所有迁移和数据库,并开始全新的迁移,这当然是不实际的,EF或我有问题吗? !

0 个答案:

没有答案