AndrewC
AndrewC

Reputation: 6730

"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!

Upvotes: 7

Views: 2328

Answers (1)

dantix
dantix

Reputation: 745

  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.

Upvotes: 9

Related Questions