# Migration - Drop FK and generate new column

**URL:** <https://www.ruby-forum.com/t/migration-drop-fk-and-generate-new-column/139514>\
**Category:** Rails\
**Created:** [June 4, 2008, 5:17pm UTC](https://www.ruby-forum.com/t/migration-drop-fk-and-generate-new-column/139514 "2008-06-04T17:17:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodrigo\_MuiSSSSo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ac8455/32.png) [@Rodrigo\_MuiSSSSo](https://www.ruby-forum.com/u/Rodrigo_MuiSSSSo)\
**Post date:** [June 4, 2008, 5:17pm UTC](https://www.ruby-forum.com/t/migration-drop-fk-and-generate-new-column/139514/1 "2008-06-04T17:17:36Z")

</div>

Guys, I need to drop some references in 4 tables and create columns that  
contain the data from the tables that are going to be decommissioned.  
Was I  
clear? :s

I was thinking in some migrations to perform the following steps:

Migration X  
1.- Create the now column  
2.- Insert the new info in the new columns recently created  
example:  
update bookings a  
set booking\_status = (select status from booking\_statuses b where  
b.id =  
a.booking\_status\_id)  
3.- Drop FK

Rollback  
1.- Generate FK  
2.- Point each FK to the corresponding record of the parent table  
3.- drop the column booking\_status of the example.

Any suggestions?

Rodrigo
