实体迁移。无法删除约束。查看以前的错误

Olr*_*ain 5 c# entity-framework entity-framework-migrations

这是产生此错误的代码。我试过重命名的解决方案,AddForeignKey但错误是一样的。

'PK_dbo.Item' 不是约束。
无法删除约束。请参阅以前的错误。

你能提出一些解决方案吗?

public override void Up()
{
    DropForeignKey("dbo.AddGallery", "item_fk_id", "dbo.Item");
    DropForeignKey("dbo.ExtraFieldValue", "item_fk_id", "dbo.Item");
    DropPrimaryKey("dbo.Item");
    AddColumn("dbo.Item", "id", c => c.Int(nullable: false, identity: true));
    AddPrimaryKey("dbo.Item", "id");
    AddForeignKey("dbo.AddGallery", "item_fk_id", "dbo.Item", "id");
    AddForeignKey("dbo.ExtraFieldValue", "item_fk_id", "dbo.Item", "id");
    DropColumn("dbo.Item", "item_id");
}

public override void Down()
{
    AddColumn("dbo.Item", "item_id", c => c.Int(nullable: false, identity: true));
    DropForeignKey("dbo.ExtraFieldValue", "item_fk_id", "dbo.Item");
    DropForeignKey("dbo.AddGallery", "item_fk_id", "dbo.Item");
    DropPrimaryKey("dbo.Item");
    DropColumn("dbo.Item", "id");
    AddPrimaryKey("dbo.Item", "item_id");
    AddForeignKey("dbo.ExtraFieldValue", "item_fk_id", "dbo.Item", "id");
    AddForeignKey("dbo.AddGallery", "item_fk_id", "dbo.Item", "id");
}
Run Code Online (Sandbox Code Playgroud)

Laj*_*pad 5

我相信主键不再存在,这就是它不能被删除的原因。