Rolling back migrations to a previous version of Entity Framework Core
During a month long refactor session on the Skyhop back-end I had upgraded all of my dependencies to their latest versions. Later during this process I discovered there was a dependency incompatibility between EF Core 5 and SqlKata. I weighted my options, and decided it would be easier to revert back to EF Core 3, than to solve this dependency compatibility issue in another way.
The process to do so had been surprisingly pleasant due to the following factors;
- I use Git. Without it I would most certainly have been screwed.
- Each time I create a new migration, I put the model changes and the migration code in different commits, which are easy to identify separately.
- I'm using a solution wide
Directory.Build.targetsfor dependency version management.
- I had not yet touched the production database, thus not requiring a rollback over there
It would be important to note that I was unable to roll back to a previous version due to changes to the API's between EF Core 3.x and 5.x, resulting in errors in some migrations, as well as errors in the model snapshot. As such, the process to do so;
- Remove migrations which are scaffolded using the 5.x version
- Grab the model snapshot from version control which is in the commit that also contains the current last available migration.
- Change the global EF Core version number in the solution wide
Directory.Build.targetsback to the latest available version. (This would be a pain to do without)
- Create a new migration using the current configuration.
Despite having upgraded to .NET Core 5, it seems like EF Core 3, still works together nicely with this setup. For now I'll be waiting until this dependency issue is resolved before I try to upgrade once again.