Skip to content

Entity Framework Core Migration Workflow

Jonathan Parker edited this page Jan 6, 2018 · 3 revisions

Working with Migrations on AllReady

If you are going to be making changes to the database you'll need to make use of EF Core migrations.

Adding migrations to the project

You will add migrations from the commandline as, at the moment, there are no tooling options in VS. Typically a migration looks like so, from the AllReadyApp/Web-App/AllReady directory:

dotnet ef migrations add _IntentOfTheMigration_

Suggested workflow

Before completing your pull request, we have found that it is easiest to avoid merge conflicts with the following steps. This ensures that your migration is created and executed in the correct order.

  • Delete your migration
  • Checkout and update master
  • Checkout your branch and rebase with master
  • Recreate your migration

Brute Force Approach

If you get into a state where migrations won't work and your DB is out of sync (you may be getting things like SqlAggregateException) then this heavy-handed approach will get your branch into the desired state before you complete your pull request.

  • Checkout and update master.
  • Delete and recreate your database by re-running the app.
  • Take a copy of the AllReadyContextModelSnapshot.cs file
  • Checkout your branch and rebase with master
  • Delete your migration and replace the model snapshot with the one from master
  • Recreate your migration
  • Run the app