How to unapply a migration in ASP.NET Core with EF Core

前端 未结 16 2247
余生分开走
余生分开走 2020-12-07 08:10

When I run PM> Remove-Migration -context BloggingContext in VS2015 with an ASP.NET Core project using EF Core I get the following error:

Syst         


        
16条回答
  •  太阳男子
    2020-12-07 08:41

    To unapply a specific migration(s):

    dotnet ef database update LastGoodMigrationName
    or
    PM> Update-Database -Migration LastGoodMigrationName
    

    To unapply all migrations:

    dotnet ef database update 0
    or
    PM> Update-Database -Migration 0
    

    To remove last migration:

    dotnet ef migrations remove
    or
    PM> Remove-Migration
    

    To remove all migrations:

    just remove Migrations folder.

    To remove last few migrations (not all):

    There is no a command to remove a bunch of migrations and we can't just remove these few migrations and their *.designer.cs files since we need to keep the snapshot file in the consistent state. We need to remove migrations one by one (see To remove last migration above).

    To unapply and remove last migration:

    dotnet ef migrations remove --force
    or
    PM> Remove-Migration -Force
    

提交回复
热议问题