EF Migrations: Rollback last applied migration?

后端 未结 15 1078
终归单人心
终归单人心 2020-12-02 03:39

This looks like a really common task, but I can\'t find an easy way to do it.

I want to undo the last applied migration. I would have expected a simple command, lik

相关标签:
15条回答
  • 2020-12-02 04:05

    I realised there aren't any good solutions utilizing the CLI dotnet command so here's one:

    dotnet ef migrations list
    dotnet ef database update NameOfYourMigration
    

    In the place of NameOfYourMigration enter the name of the migration you want to revert to.

    0 讨论(0)
  • 2020-12-02 04:07

    EF CORE

    PM> Update-Database yourMigrationName

    (reverts the migration)

    PM> Update-Database

    worked for me

    in this case the original question (yourMigrationName = CategoryIdIsLong)

    0 讨论(0)
  • The solution is:

    Update-Database –TargetMigration 201609261919239_yourLastMigrationSucess
    
    0 讨论(0)
  • 2020-12-02 04:08

    It's working for me.

    Syntax Update-Database

    Example Update-Database 20200903061032_AddNewFieldInCreditHistoryAndLogs

    0 讨论(0)
  • 2020-12-02 04:11
    update-database 0
    

    Warning: This will roll back ALL migrations in EFCore! Please use with care :)

    0 讨论(0)
  • 2020-12-02 04:11
    Update-Database –TargetMigration:"Your migration name"
    

    For this problem I suggest this link:

    https://elegantcode.com/2012/04/12/entity-framework-migrations-tips/

    0 讨论(0)
提交回复
热议问题