Open raymens opened 3 years ago
My intent was to apply a specific migration of the past but it actually reverted earlier applied migrations.
To understand better, what was your expectation when specifying a specific migration, given that your database was at a newer one? Or were you not aware at which migration your database was?
We had a migration that had an older date (with regard to the other "newer" migrations) as it was in a long-lived feature branch but was merged later than the "newer" migrations. Something like this:
So in this scenario I wanted to only apply migration 2. Without paying attention to 3 or 4 as I knew they were not related (as in, other tables etc.). Part of me only wanting to apply the 2nd one is that it was older than the other ones which were already applied. So I thought I could reduce the risk to see what would happen if I would only apply a specific migration. According to the documentation of dotnet ef database update
I did not see anything conflicting with this intent.
But when applying the migration I saw the notice of Reverting migration 3
and Reverting migration 4
.
I was fortunately able to clean that up nicely.
But to possibly make sure others don't make a similar mistake I created this issue.
The documentation I'm thinking of is something in the lines of:
Updates the database to the last migration or to a specified migration.
Specifying a specific migration will apply all migrations to to that migration and reverting any newer migrations already applied.
Update:
Thinking more about this, a simple command to get the list of applied migrations like dotnet ef database list
.
A dotnet ef database update --output sql
that would export the SQL that will be executed would be interesting aswell. Also for a confirmation and verification step within the deployment.
But that's more of a feature request than a documentation issue :)
We should consider improving the docs here.
The
dotnet ef database update
command does not mention a very important "feature". When you give a specific MIGRATION as argument, it will revert any newer migrations. My intent was to apply a specific migration of the past but it actually reverted earlier applied migrations.I understand the reasoning of this process but I would say this could really be specifically mentioned as it can cause major issues and reverting a database is no fun task.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.