EF Migrations: Rollback last applied migration?Ask Questions

 Posted on 24 days ago

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?

Share On: facebook gplus twitter
profile
Asked by Karishnamurthy Aiyar on 24 days ago Score: 32 points
Add Comment:

Comments

2 Answers

0 Corrected Answers
Aproved Answers
0
Profile
Answered by hardik chaudhary on 9/28/2019 3:24:05 PM Score: 542 points

As of EF 5.0, the approach you describe is the preferred way. One solution would be to create a wrapper PS script that automates the steps above. Additionally, feel free to create a feature request for this, or better yet, take a shot at implementing it! http://entityframework.codeplex.com/

Comments

Add Comment:
Aproved Answers
0
Profile
Answered by Ned Batchelder on 9/28/2019 8:53:54 AM Score: 35 points

In EntityFrameworkCore:

Update-Database 20161012160749_AddedOrderToCourse

where 20161012160749_AddedOrderToCourse is a name of migration you want to rollback to.

Comments

Add Comment:

Post Your Answers

Existing Members

Sign in to your account
Email Address
Password
New Member?
Sign up and complete profile
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.