如何在带有EF Core的ASP.NET Core中取消应用迁移 [英] How to unapply a migration in ASP.NET Core with EF Core

查看:430
本文介绍了如何在带有EF Core的ASP.NET Core中取消应用迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 PM>时,在带有使用EF Core的ASP.NET Core项目的VS2015中,在Remove-Migration -context BloggingContext 中,出现以下错误:

When I run PM> Remove-Migration -context BloggingContext in VS2015 with an ASP.NET Core project using EF Core I get the following error:

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。

How can I unapply it? I'm using latest release of ASP.NET Core 1.0, EF Core, and VS2015 Update 3.

推荐答案

使用:

CLI

> dotnet ef数据库更新< previous-migration-name>

Package Manager控制台

PM>更新数据库< previous-migration-name>

示例:

PM>更新数据库MyInitialMigration

然后尝试删除上一次迁移。

Then try to remove last migration.

在没有数据库更新的情况下删除迁移是行不通的,因为您对数据库应用了更改。

Removing migration without database update doesn't work because you applied changes to database.

如果使用PMC,尝试:
PM>更新数据库0
这将擦除数据库并允许您删除解决方案上的迁移快照

If using PMC, Try: PM> update-database 0 This will wipe the database and allow you to remove the Migration Snapshot on your Solution

这篇关于如何在带有EF Core的ASP.NET Core中取消应用迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆