This looks like a really common task, but I can\'t find an easy way to do it.
I want to undo the last applied migration. I would have expected a simple command, lik
Additional reminder:
If you have multiple configuration type, you need to specify the [ConfigurationName]
Update-Database -Configurationtypename [ConfigurationName] -TargetMigration [MigrationName]
I'm using EntityFrameworkCore and I use the answer by @MaciejLisCK. If you have multiple DB contexts you will also need to specify the context by adding the context parameter e.g. :
Update-Database 201207211340509_MyMigration -context myDBcontext
(where 201207211340509_MyMigration
is the migration you want to roll back to, and myDBcontext
is the name of your DB context)
I run mine through my (BASH GIT) console also running Entity Framework Core. Update-Database
commands will not work outside of the package console and I have to use the donet ef
commands.
donet ef database update [Name of previous Migration]
This will run the protected override void Down(MigrationBuilder migrationBuilder)
method of your current migration and all of the others to get back to the version of the DB you set it to.
I also use the -p [migration project]
-s [Project Solution]
. This also allows it to point to my appsettings.[Enviorment].json where my password to access DB is stored.
export ASPNETCORE_ENVIRONMENT=[ENVIORMENT]; donet ef database update [Name of previous Migration] -p [Migration Project Name] -s [Solution Name]
A lot of this might be known but wanted to give detail in case your first time doing.