Fahad Ahmed
Fahad Ahmed

Reputation: 63

Restoring tables in entity framework

I am working with EF very first time. For some reason I was having difficulty to run my application and every time I was getting exception that your model is not synced up with the current database. I tried everything and since data wasn't important, I thought to re-create all tables by running all the migrations. So, I removed all tables and tried to run the following command. I am using model based approach here to define my entities.

Update-database -targetMigration:InitialCreate -verbose

I was under the impression that it will re-create all tables starting from the very first migration but it actually reverted all to that very first point. Now, whenever i run update-database command, I always get the following

No pending explicit migrations.

I am very confused what should I do to take my table generated back and set my app in working condition. Can anybody help?

Thanks -Fahad

Upvotes: 3

Views: 1393

Answers (1)

Ryan Amies
Ryan Amies

Reputation: 4942

If you are using model first then you can click on the Model whitespace and do "Generate database from Model". If you are doing code first, EF creates a table on the database called "__MigrationHistory". If you delete that table code first will recreate the database model from your current code based model.

Upvotes: 1

Related Questions