当我在 VS2015 中运行 PM> Remove-Migration -context BloggingContext
并使用 EF Core 运行 ASP.NET Core 项目时,出现以下错误:
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> 更新数据库 0 这将删除数据库并允许您删除解决方案上的迁移快照
关于c# - 如何使用 EF Core 在 ASP.NET Core 中取消应用迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38192450/