Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find the object "dbo.Table" because it does not exist or you do not have permissions

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.

like image 523
jacobsowles Avatar asked Apr 27 '14 21:04

jacobsowles


3 Answers

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.

like image 181
Nigrimmist Avatar answered Nov 03 '22 13:11

Nigrimmist


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

like image 25
Ultroman the Tacoman Avatar answered Nov 03 '22 13:11

Ultroman the Tacoman


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.

like image 1
Aditya Raj Avatar answered Nov 03 '22 13:11

Aditya Raj