Skip to content

'dotnet ef database update' should mention that it reverts newer migrations than the target one #3061

Closed

Description

@raymens

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.

Activity

  1. roji commented on Feb 1, 2021

    @roji
    Member

    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?

  2. raymens commented on Feb 1, 2021

    @raymens
    Author

    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:

    1. Migration applied
    2. Migration NOT applied (was in a separate branch, merged later than the migrations below
    3. Migration applied
    4. 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 :)

  3. ajcvickers commented on Feb 2, 2021

    @ajcvickers
    Contributor

    We should consider improving the docs here.

  4. added this to the Backlog milestone on Feb 2, 2021
  5. added a commit that references this issue on Aug 11, 2026
    bb42937
  6. modified the milestones: Backlog, 11.0.0 on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions