I'm attempting to write a migration that adds a foreign key column to
a table to replace an existing attribute (a string to an object). I'd
like to add the column, convert the existing data into a new entry on
the foreign table and then set the foreign key value.
I'm successfully able to add the column, but it doesn't seem like the
objects mapped to the foreign table get created, as after the
migration completes the foreign table is empty and the foreign key
values are very large, seemingly random integers.
I've tried doing Object.new + Object.save and Object.create, but
neither seems to work. I've also tried both of those inside of a
transaction within the 'self.up' that's marked as ':requires_new'.
Any thoughts on what I might be doing wrong or how to debug this? Any
links to examples?