Merge migrations in entity-framework-core c# entity-framework entity-framework-core


Is it possible to merge all migrations files into one ?

I created initial migration.

dotnet ef migrations add InitialMigration


When ever I have some model change I create new migration update.

But now I have too many migration update files. Is ti possible to merge all migration files to one ?

Off course drop database is not an option, I have to preserve data !

11/22/2016 4:44:12 PM

Accepted Answer

EF 6.X has a option IgnoreChanges. That is the perfect fit for your scenario. But unfortunately it is not a feature available in EF core.

But there is a workaround.

Step 1 : Delete all the migration scripts in the Migrations folder.

Step 2 : In the package manager console : run

PM> Add-Migration InitialCreate

Step 3 : Delete both Up() and Down() methods code. Before you do this, keep those methods saved elsewhere as we will need them again in step 5.

Step 4 : run:

 PM> Update-Database

It'll insert a new record into __EFMigrationsHistory table.

Step 5 : After that fill the above migration script's (i.e. .._InitialCreate) Up() and Down() method from the content kept in a safe place from Step 3.

That is it. Now you have only 1 migration file :)

Note : EF core with Package manager console (PM) :Package Manager Console

7/17/2018 12:44:03 PM

Popular Answer

One way to do that is removing all migration files physically and adding new one. If your migrations are in "Migrations" folder, you can simply delete it, otherwise you need to delete your "ModelSnapshot" file too. I think this approach can solve your issue.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow