Add-Migration while there are explicit migrations pending

.net c# ef-code-first ef-migrations entity-framework

Question

I now face a fundamental challenge when trying to generate a migration while my model has already undergone significant modifications and my database is out of sync (up to the most recent migration, I have no database at all).

The specifics are as follows:

  1. Have an explicit migrations sequence.
  2. not a database. Have many unfinished alterations, to put it simply.
  3. modified the models and context.
  4. It will complain when you try to add migration, saying exactly that There are pending explicit migrations..
  5. If I attempt to run the migration (and synchronize my DB) using Update-Database or migrate.exe, it will fail (after applying explicit migrations successfully), in addition to the absence of automatic migrations.
  6. Additionally, I do not want to enable automatic migrations. (to prevent any schema changes to be committed and go unaccounted in code.)

I understand that I can now execute #4 following the failure in #5. Then try #5 again, and success.

Whether this is the anticipated course of action to resolve this absurd predicament is my question.

1
6
9/5/2014 2:58:04 PM

Accepted Answer

I would take the next course of action.

Apply migrations first, then specify the final one.

PM> Update-Database -TargetMigration AnyMigrationName

# It updates database to a migration named "AnyMigrationName"
# This will apply migrations if the target hasn't been applied or roll back migrations
# if it has

You merely add a new migration when your local database is updated.

PM> Add-Migration NewMigrationName

# it scaffolds a new migration named "NewMigrationName" 

In search of a reliable reference These blog postings on Migrations EF that I found may be of great assistance to you. They cover a wide range of topics, but particularly Zzz-29 Zzz and Zzz-33 Zzz.

11
9/7/2014 8:22:39 AM

Popular Answer

When you have numerous pending migrations, this error is displayed.

If you don't need existing migrations, first delete (exclude) all migration on Migration folder and then add a new migration.

Add-Migration new



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow