I have a local database instance that I recently created using DbContext.Database.Create() , so the __MigrationHistory table exists with an InitalCreate record that corresponds to the code at the moment.
However, some code-based migrations exist in the Migrations folder. They will run in our development and mid-tier environments so that these databases match the code. However, I do not need to apply them locally since I created the database using the current code.
Now I need to make changes to the model and create the appropriate migration. But when I run Add-Migration TestMigration , I get the following error
Unable to generate an explicit migration because the following explicit migrations are pending: [201203271113060_AddTableX, 201203290856574_AlterColumnY] Apply the pending explicit migrations before attempting to generate a new explicit migration.
What should I do in this case? I cannot specify the Add-Migration tool in another environment because it does not guarantee that the version matches what I have locally. I need a migration that matches only the changes I made.
I seem to have a few options, but none of them are perfect:
- Delete other migrations from the Migrations folder, run the Add-Migration command, update the database and restore the old migrations. It's simple, but it seems a little hacky.
- Go back to the version of the model in the original control that the first migration applies to, then create it and use it to create the database. Then get the latest version, apply all the migrations, then Iβm ready to add my migration. It seems like a lot of effort!
- Create a manual migration.
Does anyone have any suggestions for managing this?
Joe taylor
source share