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!
s.inspectto verify that it actually has afirst_record_pubthat isn't 1. Also try outputting the result ofnew_first_recordafter you assign themy_pubvalue to verify that it was set to whats'sfirst_record_pubis. Just a small sanity check, but it can help point you in the right direction.puts s.inspector (short cut)p sthen you will get that information outputted to your console when you try to run your migration.