Quando PM> Remove-Migration -context BloggingContext
in VS2015 con un progetto ASP.NET Core utilizzando EF Core, viene visualizzato il seguente errore:
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.
Come posso annullarlo? Sto usando l'ultima versione di ASP.NET Core 1.0, EF Core e VS2015 Update 3.
Uso:
CLI
> dotnet ef database update <previous-migration-name>
Console di gestione pacchetti
PM> Update-Database <previous-migration-name>
Esempio:
PM> Update-Database MyInitialMigration
Quindi prova a rimuovere l'ultima migrazione.
La rimozione della migrazione senza aggiornamento del database non funziona perché sono state applicate modifiche al database.
Se si utilizza PMC, provare: PM> update-database 0 Questo cancellerà il database e consentirà di rimuovere l'istantanea della migrazione sulla soluzione