0

I'm new to Code-first migration world and i need some help to understand how to rollback without problems.

I made the following EF migrations :

201512050853073_InitialCreate
201512050919315_AutomaticMigration
201512050922156_AutomaticMigration
201512051442428_add_SourceProperty
201512051447812_add_TargetProperty

The last Migration : i add property[Target] to my class and add that migration.then update my database successfully .


Now if i want to rollback the last migration : Should i just Run update-database -TargetMigration "add_SourceProperty" -verbose ?

or run the previous command then delete the [Target] property and delete also the

`201512051447812_add_TargetProperty.cs` file ?
Fabio
  • 11,892
  • 1
  • 25
  • 41
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
  • Whether you delete it or not depends on whether you might want to utilize it again. – mason Dec 05 '15 at 16:27
  • Yes you would run the command that you specified above. I probably wouldn't delete your migration file. It doesn't hurt anything to have it there and as long as it is properly named it won't get confused with anything else. – mrsargent Dec 05 '15 at 16:28
  • 1
    I have rolled back and deleted many times in my DEV environment. Another approach if it involves non DEV environments is to remove the Target property from the class and generate a new migration (remove_TargetProperty). http://stackoverflow.com/questions/22680446/entity-framework-rollback-and-remove-bad-migration – Steve Greene Dec 05 '15 at 16:55
  • When i run just the command and run the application i find the last rollback lose its effect,and when i remove the property i get `Unable to update database to match the current model because there are pending changes and automatic migration is disabled. ` ,i'm so confused – Anyname Donotcare Dec 05 '15 at 17:09

0 Answers0