简体   繁体   中英

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?

Try doing this Check if Column exist

Create new migration and add a check whether the column exist or not and if not then create a column using add_column(....).

This will not break your development as well as production code and others using the same git repository will also benefit rather than commenting the operation and uncommenting when its done

是的,这会在您的develompent数据库上引起一些问题,只需在开发数据库上运行rake db:migrate期间注释add_column命令,然后在该操作后取消注释即可。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM