PM> Remove-Migration -context BloggingContext
EF Core を使用して ASP.NET Core プロジェクトを VS2015 で実行すると、次のエラーが発生します。
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 の最新リリースを使用しています。
ベストアンサー1
使用:
コマンドライン
> dotnet ef database update <previous-migration-name>
パッケージ マネージャー コンソール
PM> Update-Database <previous-migration-name>
例:
PM> Update-Database MyInitialMigration
次に、最後の移行を削除してみます。
データベースに変更を適用したため、データベースを更新せずに移行を削除することはできません。
PMCを使用している場合は、次を試してください: PM> update-database 0 これにより、データベースが消去され、ソリューションの移行スナップショットを削除できるようになります。