Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF - Moving from AutomaticMigrations to Manual Migrations

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.

  1. Is this possible to align a model has with an automatic migration has in the migration table?
  2. 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!
  3. 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.

like image 856
codeputer Avatar asked Nov 20 '13 00:11

codeputer


1 Answers

It should be possible:

  1. Delete the __MigrationHistory table
  2. Delete any migrations in your project
  3. Disable automatic migrations in your migrations configuration class
  4. Add-Migration InitialCreate
  5. Update-Database -Script
  6. Execute the portion of the script that creates the __MigrationHistory table and inserts a row into it
  7. Repeat steps 1 & 6 for any other existing databases

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

like image 170
bricelam Avatar answered Sep 23 '22 04:09

bricelam