How the right way to rollback migration with Entity Framework

entity-framework entity-framework-6 mysql visual-studio

Question

I'm very newbie with EF and migration. I'm trying to make a rollback with the command, to run the Down method

update-database -TargetMigration MyLastMigration

Output result

Target database is already at version 201701031905415_MyLastMigration.

How can I execute the Down method of MyLastMigration?

Thanks in advance

1
2
1/3/2017 7:54:14 PM

Accepted Answer

Your target migration should be the migration immediately previous to the one that you want to rollback:

update-database -SourceMigration MyLastMigration -TargetMigration MigrationPreviousToMyLastMigration

The SourceMigration parameter is optional in your case, as you have not applied any migration after MyLastMigration.

To check the name of the previous migration you can use Get-Migrations, that returns the list of migrations applied to your database.

Edit: as Ivan Stoev says in the comments, the SourceMigration parameter can only be included together with the parameter Script, so it does not make sense in this scenario. The right command would be like this:

update-database -TargetMigration MigrationPreviousToMyLastMigration
3
1/3/2017 8:56:50 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow