Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I undo the last Add-Migration command?

I have created a migration using the Add-Migration command, but I'd like to change the name of that migration. How can I undo the migration command, so that I can regenerate it using the new desired name?

Is it just a matter of deleting the generated files, or this could be a bad idea?

like image 432
Miguel Angelo Avatar asked Jan 23 '14 15:01

Miguel Angelo


People also ask

How do I rollback migration?

You can rollback your migration by using rake db:rollback with different options. The syntax will be different according to your requirements. where n is number of migrations to rollback, counting from latest migration.

How do I revert a migration in Entity Framework?

Reverting a Migration But, for some reason, you want to revert the database to the previous state. In this case, use the update-database <migration name> command to revert the database to the specified previous migration snapshot. > dotnet ef database update MyFirstMigration.


2 Answers

If you haven't used Update-Database you can just delete the migration file. If you've run the update you should roll it back using Update-Database -TargetMigration "NameOfPreviousMigration" then delete the migration file.

Reference:

http://elegantcode.com/2012/04/12/entity-framework-migrations-tips/

like image 88
Colin Avatar answered Oct 19 '22 05:10

Colin


If you haven't executed the migration yet with Update-Database, you can run Add-Migration again with the same name (you may need to use -Force) to re-execute the scaffolding. This is noted in the output of the Add-Migration command.

like image 35
Adrian Avatar answered Oct 19 '22 06:10

Adrian