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

前端 未结 16 2307
余生分开走
余生分开走 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:43

    To "unapply" the most (recent?) migration after it has already been applied to the database:

    1. Open the SQL Server Object Explorer (View -> "SQL Server Object Explorer")
    2. Navigate to the database that is linked to your project by expanding the small triangles to the side.
    3. Expand "Tables"
    4. Find the table named "dbo._EFMigrationsHistory".
    5. Right click on it and select "View Data" to see the table entries in Visual Studio.
    6. Delete the row corresponding to your migration that you want to unapply (Say "yes" to the warning, if prompted).
    7. Run "dotnet ef migrations remove" again in the command window in the directory that has the project.json file. Alternatively, run "Remove-Migration" command in the package manager console.

    Hope this helps and is applicable to any migration in the project... I tested this out only to the most recent migration...

    Happy coding!

提交回复
热议问题