When I run PM> Remove-Migration -context BloggingContext
in VS2015 with an ASP.NET Core project using EF Core I get the following error:
Syst
To unapply a specific migration(s):
dotnet ef database update LastGoodMigrationName
or
PM> Update-Database -Migration LastGoodMigrationName
To unapply all migrations:
dotnet ef database update 0
or
PM> Update-Database -Migration 0
To remove last migration:
dotnet ef migrations remove
or
PM> Remove-Migration
To remove all migrations:
just remove Migrations
folder.
To remove last few migrations (not all):
There is no a command to remove a bunch of migrations and we can't just remove these few migrations
and their *.designer.cs
files since we need to keep the snapshot file in the consistent state. We need to remove migrations one by one (see To remove last migration
above).
To unapply and remove last migration:
dotnet ef migrations remove --force
or
PM> Remove-Migration -Force
Add-Migration "migration-name"
Up(){ //paste here }
Update-Database
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!
Use:
CLI
> dotnet ef database update <previous-migration-name>
Package Manager Console
PM> Update-Database <previous-migration-name>
Example:
PM> Update-Database MyInitialMigration
Then try to remove last migration.
Removing migration without database update doesn't work because you applied changes to database.
If using PMC, Try: PM> update-database 0 This will wipe the database and allow you to remove the Migration Snapshot on your Solution
To revert all the migrations which are applied to DB simply run:
update-database 0
It should be followed with running Remove-Migration
as many times as there are migration files visible in the Migration directory. The command deletes the latest migration and also updates the snapshot.
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).