Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a migration again, without deleting all the newer migrations?

I had just installed devise so the table didn't have any data on it except one user (me).

I was re-doing the database all over again so I dropped it all. I did rails g scaffold to generate 6 new models and controllers and did rake db:migrate

In my /db/migrate directory I have the devise file with the filename 20130603211907_devise_create_users.rb

Here is the issue: If I do rake db:migrate:down VERSION=20130603211907 it will delete all the new migrations.

How do I run a migration again, without deleting all the newer migrations?

like image 584
Kush Avatar asked Jun 07 '13 09:06

Kush


People also ask

Does migration delete data?

No it does not. unless you edited your old migrations you already ran on the server, which will change the order of how changes to the db are applied. Migrations are applied to the database sequentially.


1 Answers

It will run the down and then the up step (This command can drop your table!):

rake db:migrate:redo VERSION=xxxxxxx

To prevent your table from being deleted you could do this in conjunction with commenting out the down step temporarily.

like image 103
Sachin R Avatar answered Sep 19 '22 18:09

Sachin R