Konrad
Konrad

Reputation: 7198

Proper way to work with migrations during development

How to properly work with migrations during development when the model is not in its final form or there are still some inconsistencies in relations?

Similar questions:

How to deal with database changes during development with EF Core?

Upvotes: 0

Views: 86

Answers (1)

alsami
alsami

Reputation: 9815

1: I personally would keep it as a history. Of course you could always delete all migrations and create one that contains everything but imagine that migration after you have added 100++ tables (entity-types) and you cannot make sure your production database for instance is being updated, when you only have one migration with same name that you just always recreate.

2: Yes, you should indeed make small migrations. You can undo a migration by updating your database to a specific migration and then removing all the others before step by step. This at least works with the package-manager-console tool (maybe also with dotnet tool).

For instance you have already added a migration with models that have changed you go back to the old migration by using this command:

Update-Database -Migration MyMigrationBeforeBadModelMigration

Be aware that this might drop tables if some were added in the migration that you want to undo.

Then remove bad migrations step by step

Remove-Migration // will always remove the latest migration so repeat that if you have many to remove

Then just create the new and proper migration and update your db.

3: Yes, give them proper names. For instance CustomerEntityAdded or CustomerUniqueNameIndexAdded.

Upvotes: 1

Related Questions