当我使用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>
程序包管理器控制台
PM> Update-Database <previous-migration-name>
例:
PM> Update-Database MyInitialMigration
然后尝试删除上一次迁移。
在没有数据库更新的情况下删除迁移不起作用,因为您已将更改应用于数据库。
如果使用PMC,请尝试:PM> update-database 0这将擦除数据库并允许您删除解决方案上的迁移快照。