Here is the code that produce this error. I've tried solution for renaming the AddForeignKey
but the error is same.
'PK_dbo.Item' is not a constraint.
Could not drop constraint. See previous errors.
Can you suggest some solution?
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");
}
I believe the primary key no longer exists and this is why it cannot be dropped.
I find an solution for this problem. Because I've trying to change the name of the existing primary key name, I encountered an error while migration because that primary key was referenced to other tables. So the solution was simply to add [Column("id")] DataAnnotation and than make the migration. Column name of the primary key was successfully changed without any error.