Merging migration entries in Entity Framework

.net c# ef-migrations entity-framework entity-framework-6


I have a CF project for Entity Framework 6 that already has a few migrations set up.

Since the model is now stable, the existing migration history does not need to be preserved.

Is it possible to restart the model and include every migration command in the first migration?

A unique, non-clustered index, for instance, is added during the second migration whereas a column is added during the first. I now desire to observe all of these changes inOnModelCreating instead of through distinct migrations.

3/7/2015 7:12:18 AM

Accepted Answer

Migrations include aUp and Down . You can always remove the existing migrations and then add a new migration to re-scaffold your application. TheDown Your model is unaffected by the process; only the database is altered. UseUpdate-Database -Target:migrationTargetName or Update-Database -TargetMigration:migrationNumber .

You may demolish every migration with if you want one that begins with no database and ends with your existing model.Update-Database -TargetMigration:0 . It makes sense to delete the database before runningUpdate-Database as a test to ensure that all database changes are coordinated.

Keep in mind that if you remove your migrations to0 then perform anAdd-Migration , you should carefully examine the generated scaffold because it is quite likely to differ greatly from the incremental changes.

3/7/2015 3:39:28 AM

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