0

I Use code-first migration but I has error when run application. error:Cannot find the object "dbo.Products" because it does not exist or you do not have permissions. I have already got deleted Products table manually on sql server.I expect when Re-Run Project All table recreate if not exist in sql server.

In addition,I write 2 line for configure migration.

AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; 

any help ?

1 Answer 1

1

If you are using migrations you shouldn't "manually" change the database. So now EF is generating code to remove the table for you, but it doesn't exist. Solution is to comment out the code in the Up() method that removes the table and update-database. See https://msdn.microsoft.com/en-US/data/dn481501

If you want your database recreated, you will need to switch to an initializer such as DropCreateDatabaseIfModelChanges. See http://www.entityframeworktutorial.net/code-first/database-initialization-strategy-in-code-first.aspx.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.