Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Migration. Could not drop constraint. See previous errors

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");
}
like image 433
Olrhain Avatar asked Oct 19 '22 11:10

Olrhain


1 Answers

I believe the primary key no longer exists and this is why it cannot be dropped.

like image 155
Lajos Arpad Avatar answered Oct 27 '22 11:10

Lajos Arpad