Reputation: 1074
In a rails project, we are attempting to migrate data from one table to another. When we create the original table, we use (snippet):
create_table :my_original_table do |t|
#OTHER COLUMNS HERE
t.integer :first_record_pub
end
Then, when we create the second table to migrate to, we use:
create_table :my_second_table do |t|
#OTHER COLUMNS HERE
t.integer :my_pub
end
and finally, when we migrate the actual data, we use:
original_value = MyOriginalTable.all
original_value.each do |s|
new_first_record = MySecondTable.new
#OTHER DATA MIGRATIONS HERE
new_first_record.my_pub = s.first_record_pub
new_first_record.save
end
All of the other columns that we migrate (the ones I commented out) migrate perfectly. However, in the migrated my_second_table, the my_pub column has some entries that are blank (expected, as some entries in the original table are blank), and the other entries simply have a value of '1'. The correct first_record_pub value was not correctly migrated over, for some reason.
Does anyone have any ideas as how to solve this issue? Thanks!
Upvotes: 0
Views: 190
Reputation: 33954
Are you both creating a new column, and trying to move data into that column in the same migration? If so you, may either need to make a call to reset_column_information between creating the column and moving data to it, OR, separate the creation and moving of data into two separate migrations.
Upvotes: 1