Entity Framework rollback and remove bad migration

后端 未结 8 2276
[愿得一人]
[愿得一人] 2020-12-12 09:01

I\'m using EF 6.0 for my project in C# with manual migrations and updates. I have about 5 migrations on the database, but I realised that the last migration was bad and I do

8条回答
  •  感情败类
    2020-12-12 09:18

    I am using EF Core with ASP.NET Core V2.2.6. @Richard Logwood's answer was great and it solved my problem, but I needed a different syntax.

    So, For those using EF Core with ASP.NET Core V2.2.6 +...

    instead of

    Update-Database 
    

    I had to use:

    dotnet ef database update 
    

    And instead of

    Remove-Migration
    

    I had to use:

    dotnet ef migrations remove
    

    For --help i had to use :

    dotnet ef migrations --help
    
    
    Usage: dotnet ef migrations [options] [command]
    
    Options:
      -h|--help        Show help information
      -v|--verbose     Show verbose output.
      --no-color       Don't colorize output.
      --prefix-output  Prefix output with level.
    
    Commands:
      add     Adds a new migration.
      list    Lists available migrations.
      remove  Removes the last migration.
      script  Generates a SQL script from migrations.
    
    Use "migrations [command] --help" for more information about a command.
    

    This let me role back to the stage where my DB worked as expected, and start from beginning.

提交回复
热议问题