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, like
PM> Update-Database -TargetMigration:"-1"
Instead, all I can come up with is:
PM> Get-Migrations
Retrieving migrations that have been applied to the target database.
201208012131302_Add-SystemCategory
201207311827468_CategoryIdIsLong
201207232247409_AutomaticMigration
201207211340509_AutomaticMigration
201207200025294_InitialCreate
PM> Update-Database -TargetMigration:"CategoryIdIsLong"
(At least I can use just the name, skipping the timestamp...)
Is there an easier way?
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, andmyDBcontext
is the name of your DB context)