Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accidentally deleted records in __MigrationHistory?

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?

like image 620
ca9163d9 Avatar asked Jun 17 '13 05:06

ca9163d9


1 Answers

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

  • delete complete database, let entity framework rebuild it from scratch (for dev ok, you will lose your data)
  • create a second database, apply all migrations which were already done on the original and copy-paste the missing contents of the __MigrationHistory table.
like image 196
Mark van Straten Avatar answered Sep 19 '22 12:09

Mark van Straten