Reputation: 29227
I accidentently deleted records in __MigrationHistory. I got the following error message when trying to Add-Migration
for model changes.
Unable to generate an explicit migration because the following explicit migrations are pending: [201303101108238_InitialCreate, 201304020555457_xxx, 201305070251407_xxx, 201306090833462_xxx, 201306140437274_xxxx]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
It will get the following error if running Update-Database
.
There is already an object named 'TableName' in the database.
What I can do to make it work?
Upvotes: 6
Views: 3358
Reputation: 2782
In addition to what Mark mentioned, you could also find migration file (the one that you delete from __MigrationHistory table) in Migration folder, and comment code inside methods Up and Down then run Update-database. It should work.
Upvotes: 4
Reputation: 9425
The __MigrationHistory table contains all the information for Entity Framework to determine which migrations are done. Based on the current list of migrations in your code it will apply the missing migrations.
If you have deleted this table without the database part you have a few options
Upvotes: 6