Rails - 强制数组:true到序列化字段

时间:2018-03-23 15:39:47

标签: ruby-on-rails serialization migration

在我的Rails应用 schema.rb 中,我有:

create_table "reviews", force: :cascade do |t|
  t.integer  "user_id"
  t.integer  "venue_id"
  t.integer  "rating",              limit: 2
  t.text     "body"
  t.datetime "created_at",                      null: false
  t.datetime "updated_at",                      null: false
  t.string   "treatments"
end

"处理"是一个序列化的字段:

class Review < ActiveRecord::Base
  serialize :treatments
  ...
end

我需要迁移&#34;治疗&#34;字段:

t.string   "treatments", default: [], null: false, array: true

适当的迁移会是什么样的?

1 个答案:

答案 0 :(得分:1)

您正在迁移中寻找change_column方法。

change_column :reviews, :treatments, :string, array: true, default: [], null: false

点击此处查看更多详情和选项:http://guides.rubyonrails.org/active_record_migrations.html#changing-columns