更新时间:2023-01-01 11:27:24
使用 Rails 5.1.x 和 PostgreSQL 9.4,以下是将文本列(包含有效的 json)转换为 jsonb 列时对我有用的方法:
Using Rails 5.1.x and PostgreSQL 9.4, here is what worked for me when converting text columns (containing valid json) to jsonb columns :
class ChangeTextColumnsToJson < ActiveRecord::Migration[5.1]
def change
change_column :table_name, :column_name, :jsonb, using: 'column_name::text::jsonb'
end
end