Search code examples
ruby-on-railsrails-migrations

My production database is missing some columns. How can I safely restore them?


After making some major modifications to a Rails app that is already in production, I pushed everything to the server, ran my migrations and then discovered major problems.

It turns out that there are 2 database columns that have not been created in my production database by the migrations. When I look through my migrations there isn't one that creates those columns. I'm guessing I made an error with git at some point and have lost those files.

What I want to know is how to safely create those columns in my production database. If I just create a new migration to make those 2 columns, push to production and run the migrations, I presume things will work, but will this cause problems when these migrations get run on my development database with the columns already there?


Solution

  • Yes this will cause some problem on your develompent database, just comment add_column commands during running rake db:migrate on your development database, and uncomment after that operation.