如何使用EF Core在ASP.NET Core中取消應用遷移

.net-core asp.net-core c# entity-framework-core visual-studio-2015

當我使用EF Core使用ASP.NET Core項目在VS2015中運行PM> Remove-Migration -context BloggingContext ,我收到以下錯誤:

System.InvalidOperationException: The migration '20160703192724_MyFirstMigration' has already been applied to the database. Unapply it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration.    at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force) 
    at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.RemoveMigration(String contextType, Boolean force) 
    at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsRemoveCommand.<>c__DisplayClass0_0.<Configure>b__0() 
    at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) 
    at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args) 
 The migration '20160703192724_MyFirstMigration' has already been applied to the database. Unapply it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration.

我該如何取消申請?我正在使用最新版本的ASP.NET Core 1.0,EF Core和VS2015 Update 3。

熱門答案

使用dotnet ef database update <previous-migration-name>

然後嘗試刪除上次遷移。

刪除沒有數據庫更新的遷移不起作用,因為您將更改應用於數據庫。



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow