Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Rebasing" EF migrations

Sorry if this is already answered - saw nothing on searching.

I have a lot of EF migrations in my project, and to be honest it has become a bit of a mess. Between my git branching screwing up the migrations and what not, I'd like to see if there's a solution for this headache.

I want to "rebase" my migrations. Is this possible? Is there an "official" way to do it?

By rebase, I mean tell EF to look at my database schema as it is right now and create me a single migration that satisfies the schema.

Thanks!

like image 728
AndrewC Avatar asked Aug 28 '13 22:08

AndrewC


1 Answers

  1. Delete your existing migrations
  2. Add-Migration SetupDatabaseFromScratch
  3. Update-Database

Ah, almost forgot - backup everything

And you should truncate your _MigrationHistory table from tyour database if you want to keep your data. But once again, make backups before doing such thing.

like image 104
dantix Avatar answered Sep 27 '22 23:09

dantix