Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stuck in EF migration limbo

Tags:

i have somehow gotten my EF5 project into a state where I can't proceed.

When I do an 'update-database' i get:

Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration. You can use the Add-Migration command to write the pending model changes to a code-based migration.

ok, fine, so i try to 'add-migration', and i get:

Unable to generate an explicit migration because the following explicit migrations are pending: [ ]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

20 GOTO 10 ??

what am i supposed to do at this point? (beyond switching to NHibernate?)

like image 544
Spongman Avatar asked Jun 06 '13 01:06

Spongman


People also ask

How do I get rid of migration?

Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.

How do I migrate in Entity Framework?

Following is the context class. Step 1 − Before running the application you need to enable migration. Step 2 − Open Package Manager Console from Tools → NuGet Package Manger → Package Manger Console. Step 3 − Migration is already enabled, now add migration in your application by executing the following command.


1 Answers

What worked for me was:

  1. Reverting all my changes (making a backup first) back to a known good state.
  2. Doing add-migration DummyMigration. That produced some spurious changes that I commented
  3. Called update-database to add the migration + metadata to the [__MigrationHistory] table.
  4. Make the changes I needed (from the backup of the code I took earlier).
  5. Do the normal add-migration/update-database.

Not ideal, and would be cool to see if there's a better solution, but that worked for me.

like image 98
Davy8 Avatar answered Sep 17 '22 21:09

Davy8