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

标签 c# entity-framework entity-framework-migrations

这是产生此错误的代码。我已经尝试过重命名 AddForeignKey 的解决方案,但错误是相同的。

'PK_dbo.Item' is not a constraint.
Could not drop constraint. See previous errors.

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

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");
}

最佳答案

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

关于c# - 实体迁移。无法删除约束。查看以前的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30429923/

相关文章:

c# - 我可以将 ComboBox 和简单的 Button 嵌入到 WinForms 中的 StatusStrip 中吗?

entity-framework - Entity Framework 5 中的 "soft deleting"

c# - Entityframework RC1 - MetadataItem.Annotations made internal - 替代方案?

entity-framework-5 - Entity Framework 迁移和播种特定更新

entity-framework - 为什么我无法将 Entity Framework 迁移到初始状态?

c# - Entity Framework 迁移-使用现有条目的值添加新列

c# - 将 double 日期和时间值转换为另一个时区?

c# - Unity从服务器下载视频并保存

c# - 标签上的透明标签

c# - Entity Framework - 有条件地包括相关实体