我正在进行迁移,我将从一个表保存为ruby Hash的数据移动到另一个表。该列保存为:text,在模型中,序列化被定义为哈希。
我想将此列移动到另一个表中但是如果我删除指定序列化类型的行(我想要做的因为该字段将不再存在),则迁移会将数据视为字符串。是否可以定义如何在迁移文件本身中序列化数据?因此,未来从头开始的迁移不会在这一点上破裂。
是的,只需在迁移文件中定义所有需要的信息:
# db/migrate/20190219114703_move_data_to_another_table.rb
class MyModel < ApplicationRecord
# here you need only the line that specifies the serialisation type
end
class MoveDataToAnotherTable < ActiveRecord::Migration[5.1]
def change
# here goes the migration itself
end
end