You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'dotnet ef database update' should mention that it reverts newer migrations than the target one #3061
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.
ID: 4d1bdeea-0ebc-04ff-5b58-1020ad9cd72a
Version Independent ID: 847fe92a-2940-afbf-b2ee-e68f8a8060be
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:
Migration applied
Migration NOT applied (was in a separate branch, merged later than the migrations below
Migration applied
Migration applied
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 :)
Activity
roji commentedon Feb 1, 2021
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?
raymens commentedon Feb 1, 2021
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 updateI did not see anything conflicting with this intent.But when applying the migration I saw the notice of
Reverting migration 3andReverting 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:
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 sqlthat 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 :)
ajcvickers commentedon Feb 2, 2021
We should consider improving the docs here.
Expand and clarify migrations guidance. (dotnet#5445)