EF Core 2.1. How to revert migration "n" steps back

c# entity-framework-core

Question

Is it possible to revert database migrations on N steps back, like,
"revert 2 migrations back"

I found in the docs that we can pass parameter '0' which will revert a database to clean state. dotnet ef database update 0

I am looking for something similar to: dotnet ef database update -2

I know, that I can do this using migration's name. But I find that sometimes much easier just enter a number, than copy/paste migration name

1
4
6/1/2018 1:55:48 PM

Popular Answer

In package manager console, you can run the following command to rollback the migrations in your database:

Update-Database NameOfPreviousMigration

Then to the remove the migrations you can run the command Remove-Migration in PMC to remove the penultimate migration. Run this as many times to remove the migrations, e.g. run twice to remove the last 2 migrations. This command will also updated your ModelSnapshot.

0
5/24/2019 9:51:07 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow