Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 387
Aliaksei Zhukau Avatar asked Jun 01 '18 13:06

Aliaksei Zhukau


1 Answers

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.

like image 123
ViqMontana Avatar answered Sep 22 '22 04:09

ViqMontana