Question

If I have two migrations, mig1 and mig2, I run rake db:migrate, then I go back to mig1 and change the default value of a column, will this change be reflected when I run rake db:migrate again? Or do I have to make a new migration just for that column to make the change?

Was it helpful?

Solution

You should either make a new migration or use the rake db:rollback task to move back to the version of your database before the migration in question was ran. Changes to migration scripts won't be automatically picked up.

The current version of your schema is tracked and applied to migrations, so running rake db:migrate will not rerun old migrations. It is for this reason that you are able to use the rollback feature, as long as you provided correct self.down methods on your migration. Rolling back executes these down methods, undoing the migrations as it goes.

You can then edit the migration and re-migrate.

OTHER TIPS

You can redo a given VERSION by running the following:

rake db:migrate:down VERSION=___________

rake db:migrate:up VERSION=____________

rake db:migrate:redo VERSION=____

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top