0

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?

  • Should migrations be treated more as commits in version control system like git and represent even the smallest change, or what?

  • Should I add new migration for each small change in my model, or should I just re-create the database and initial migration until I'm satisfied with how my model looks? I can still remove all those migrations in the end and create initial one to clean those small migrations up.

  • How to properly name migrations? Most often I can't come up with a good name and I give them some meaningless names like X1, X2, X3

Similar questions:

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

Konrad
  • 6,385
  • 12
  • 53
  • 96
  • 1
    During Dev, I could usually care less about how I got to my first deployment. It is code first and my classes are source controlled. When I get to the point where I care about my test data, I introduce migrations. – Steve Greene Aug 02 '18 at 13:54

1 Answers1

1

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.

alsami
  • 8,996
  • 3
  • 25
  • 36