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

33,490

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
33,490
jacobsowles
Author by

jacobsowles

Updated on July 05, 2022

Comments

  • jacobsowles
    jacobsowles almost 2 years

    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.

  • Toolkit
    Toolkit over 8 years
    may be better reinstall windows or change country?
  • SWilko
    SWilko over 7 years
    was looking for ages trying to work this out. Thanks :)
  • Nigrimmist
    Nigrimmist about 6 years
    @ShashankKuchibhotla, using db migration class, please read any article related db migrations through entity framework
  • Ultroman the Tacoman
    Ultroman the Tacoman over 2 years
    Depending on the size of the database, definitely.
  • Ifeanyi Chukwu
    Ifeanyi Chukwu over 2 years
    Maybe better set the machine on fire.