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.
How can I unapply it? I'm using latest release of ASP.NET Core 1.0, EF Core, and VS2015 Update 3.
To revert the last applied migration you should (package manager console commands):
PM> Update-Database <prior-migration-name>
PM> Remove-Migration
UPD: The second step seems to be not required in latest versions of Visual Studio (2017).
To "unapply" the most (recent?) migration after it has already been applied to the database:
Hope this helps and is applicable to any migration in the project... I tested this out only to the most recent migration...
Happy coding!
In order to unapply a migration in EF Core 1.0 use the command:
dotnet ef database update {migration_name}
Use the migration name of the migration until which you would like to preserve your changes. The list of names of the migration can be found using:
dotnet ef migrations list
In general if you are using the Package Manager Console the right way to remove a specific Migration is by referencing the name of the migration
Another way to remove the last migration you have applied according to the docs is by using the command:
This command should be executed from the developer command prompt (how to open command prompt) inside your solution directory.
For example if your application is inside name "Application" and is in the folder c:\Projects. Then your path should be:
To completely remove all migrations and start all over again, do the following: