当我在使用EF核心的ASP.NET核心项目中运行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核心1.0、EF核心和VS2015更新3的最新版本。
发布于 2016-11-28 02:22:22
要完全删除所有迁移并重新开始,请执行以下操作:
dotnet ef database update 0
dotnet ef migrations remove
发布于 2016-07-05 17:29:05
您仍然可以使用Update-Database
命令。
Update-Database -Migration <migration name> -Context <context name>
但是,从您的迁移名称判断,我假设这是第一次迁移,因此该命令可能不起作用。您应该能够从数据库的__MigrationHistory
表中删除该条目,然后再次运行Remove-Migration
命令。您也可以删除迁移文件,然后重新开始。
发布于 2018-03-19 17:05:15
简单地说,您可以通过值确定迁移目标
Update-Database -Migration:0
然后继续并删除它
Remove-Migration
https://stackoverflow.com/questions/38192450
复制相似问题