Combining migration records in the Entity Framework

I have an Entity Framework 6 CF project that already has several migrations.

Now the model is stable and there is no need to maintain a migration history that already exists.

Is there a way to reset the model and combine all the migration commands into the original migration?

As an example, the first migration adds a column, and the second migration adds a unique, non-clustered index. Now I want to see all these changes directly in OnModelCreating , and not in separate transitions.

+7
c # entity-framework code-first-migrations entity-framework-6
source share
1 answer

Migrations have both Up and Down . You can always remake your application by breaking the migration down, and then adding a new migration. The Down process does not change your model, but only changes in the database. Use Update-Database -Target:migrationTargetName or Update-Database -TargetMigration:migrationNumber .

If you want to perform a migration that starts without a database and ends with the current model, you can delete all migrations using Update-Database -TargetMigration:0 . It is a good idea to demolish the database and then run Update-Database as a test to verify that the database changes are in sync.

Remember, if you break your migrations to 0 , and then run Add-Migration , you will need to look very carefully at the generated scaffold, as it will probably be significantly different from incremental changes.

+6
source share

All Articles