I was having some issues with my Table model when trying to Update-Database, so I decided to just delete the table and start from scratch. To do this, I removed the table through Visual Studio's Server Explorer. But now when I try to Update-Database again with a new version of the Table model, I get the error "Cannot find the object "dbo.Table" because it does not exist or you do not have permissions."
How do I fix this? I have the model, but I can't get the SQL table to generate.
If you rename table during migration, double check that order of rename is correct :
DropForeignKey("dbo.PartnerTransactions", "partnerID", "dbo.Partners");
RenameTable(name: "dbo.PartnerTransactions", newName: PaymentTransactions");
not correct :
RenameTable(name: "dbo.PartnerTransactions", newName: PaymentTransactions");
DropForeignKey("dbo.PartnerTransactions", "partnerID", "dbo.Partners");
And etc! Rename should go after all drops and old_table_name manipulations. Sometimes EF is a slowpoke.
This answer helped me and many others. If it doesn't work to just remove the __Migrations-table, try to remove all tables in the DB, and do an update-database -force
Delete the code inside the Up method and down method. then run the command Update-database
public override void Up()
{
//Delete the code
}
public override void Down()
{
//Delete the code
}
then it's working perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With