Skip to content

Migrations: Provide easy way to get script from latest applied on database to latest in the codebase #15762

Description

@divega

This is what Update-Database -Script does by default in EF6 and it feels very natural, but in EF Core, that isn't available, so you need to run other commands to find out what the latest migration applied is before you can pass that to Script-Migration -From argument.

See Twitter thread about this:

Migrations in EF Core are a pain in the ass.

* Nearly impossible to tell which connection string your getting
* Several issues with model changes not showing up (had to blow away and start over).
* Command Line tooling not working.

Seems like 2 steps back from EF6. #efcore pic.twitter.com/M9V60Zl5RA

— Rick Strahl (@RickStrahl) May 19, 2019

cc @bricelam @RickStrahl

Activity

  1. bricelam commented on May 20, 2019

    @bricelam
    Contributor

    I think we have a few open PRs (and/or items on the backlog) that would enable you to do something like this:

    Script-Migration -From (Get-Migration | where Applied -eq $true | select -Last)
  2. RickStrahl commented on May 20, 2019

    @RickStrahl

    Thanks for that @bricelam - that's helpful!

    But it sure would be nice to have that as something you don't have to remember like a --pending flag. I would even argue that this should be the default. The 90% use case is that you want to apply pending changes to the database.

    Actually come to think of this I think this behavior would be better provided with update-database --script just as it did in EF6. Script-Migration isn't obviously tied to a DB Operation so it's kind of out of scope. But update-database --script makes good sense IMHO and you have to be generating the script to update the database anyway. Not only does that provide the script it also lets you preview the actual changes that are being made - currently update-database feels just like a complete black box.

  3. added this to the Backlog milestone on May 31, 2019
  4. modified the milestones: Backlog, 7.0.0 on Oct 22, 2021
  5. modified the milestones: 7.0.0, Backlog on Jul 7, 2022
  6. Devvox93 commented on Feb 8, 2023

    @Devvox93

    I'm very eager to use such functionality, as I'm sure many others with me.
    The 7.0.0 milestone is closed, but this issue is still open.
    Any news? Related issues/PRs with more progress maybe? I've been looking around with references, but am unsure which is "the" place to measure progress.

    @bricelam You seem to have been involved in many of these issues/PRs. Could you shed a light on the status?
    I believe this has been made possible with #22109, right?
    But this issue is about making it easier with a new command option.

  7. ajcvickers commented on Feb 8, 2023

    @ajcvickers
    Contributor

    @Devvox93 Unfortunately, this did not make it into EF7. As of now, the issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 8.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you. Right now this issue has only one vote, which makes it very low priority compared to many other issues.

  8. Devvox93 commented on Feb 9, 2023

    @Devvox93

    @ajcvickers Thanks for the update and clarification. Seeing the number of votes, perhaps this issue will even be unnecessary.
    Then, however, it'd be nice if some of the script examples Brice has put here and there could be added to the documentation of, for example, Get-Migration or Script-Migration.
    Since I'm currently working with this, I'll add some examples to the docs through a PR when I'm done.

  9. removed their assignment
    on Jul 8, 2023
  10. glen-84 commented on Sep 15, 2023

    @glen-84

    Quite unbelievable that this issue only had 2 votes. I just want to output the SQL for unapplied migrations, for review purposes. Using scripts is the recommended method of deployment, yet it's not possible to simply view the pending SQL.

  11. glen-84 commented on Sep 15, 2023

    @glen-84

    It's not even possible to generate the script for a single migration without providing the name of the previous migration. 😞

    (confusion)

  12. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions