EF - Moving from AutomaticMigrations to Manual Migrations

entity-framework, entity-framework-migrations

Solution

It should be possible:

- Delete the __MigrationHistory table

- Delete any migrations in your project

- Disable automatic migrations in your migrations configuration class

- Add-Migration InitialCreate

- Update-Database -Script

- Execute the portion of the script that creates the __MigrationHistory table and inserts a row into it

- Repeat steps 1 & 6 for any other existing databases

I also strongly recommend reading Code First Migrations in Team Environments.

Problem

End of long day of testing various scenarios where I don't have to recreate a production database... We started off with EF, and didn't get wise enough during development to move from automatic migrations to named migrations. Now I'm trying to rewind the clock, and create an initial migration that aligns with the production database. - Is this possible to align a model has with an automatic migration has in the migration table? - Should I just create an empty migration to get started with named migrations? My only problem with this is how to create the DB when a new developer joins... I could simply restore the db, and then apply migrations, but that ruins a beautiful EF migration story! - Delete the production DB, create, and write a script to re-import the data (sounds hacky). Another wrinkle - the DB was created with EF5, and we are now developing with EF6. Thanks in advance for your help.

Original source