我目前有以下数据库架构:
create_table :user_actions do |t|
t.integer :emitter_id
t.string :emitter_type
t.integer :target_id
t.string :target_type
t.json :payload
t.timestamps
end
我希望将json
中的payload
字段迁移到hstore
中。
步骤如下:
change_column :user_actions, :payload, :hstore
以下是错误信息的结果:
PG::DatatypeMismatch: ERROR: column "payload" cannot be cast automatically to type hstore
HINT: Specify a USING expression to perform the conversion.
不确定如何使用USING
提示符以及在不丢失任何数据的情况下进行此迁移的最佳方法?
o.new_field = o.payload
,其中new_field
是一个hstore
。 - Pierre-Louis Gottfrois