Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rollback a single migration file in rails?

I only want to undo one migration file, something like

rake db:rollback VERSION=$TIMESTAMP

This command doesn't work. Any suggestion?

like image 767
mko Avatar asked Dec 20 '10 10:12

mko


People also ask

How do you roll back migration?

The part with migrate:rollback is the actual command. It says that you want to rollback certain database migrations. The last part, --step=1 , is a parameter for the migrate:rollback command. By default, php artisan migrate:rollback will rollback all of your database migrations.

How do I rollback a particular migration in laravel?

If you want to rollback a specific migration, look in your migrations table, you'll see each migration table has its own batch number. So, when you roll back, each migration that was part of the last batch gets rolled back.

How do I rollback models in rails?

To undo a rails generate command, run a rails destroy command. You can then edit the file and run rake db:migrate again. (See how to roll back a Migration file to rollback a specific migration or multiple migrations.)

Can you edit a migration file rails?

If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run rake db:migrate.


2 Answers

rake db:migrate:down VERSION=$TIMESTAMP should do the trick.

like image 105
cdmwebs Avatar answered Oct 14 '22 04:10

cdmwebs


rake db:rollback is now the way.

like image 41
sirfilip Avatar answered Oct 14 '22 04:10

sirfilip