我看了How to add a Hash object to an ActiveRecord class? Tried but migration fails并按照那里的格式。
我试过了:
class AddTestResponsesToSurveys < ActiveRecord::Migration
def change
add_column :surveys, :responses, :hash
end
end
当我运行rake db:migrate
时,我在schema.rb
文件中收到错误消息:
# Could not dump table "surveys" because of following StandardError
# Unknown type 'hash' for column 'responses'
我做错了什么?
答案 0 :(得分:1)
使用列类型文本生成迁移
class AddTestResponsesToSurveys < ActiveRecord::Migration
def change
add_column :surveys, :responses, :text
end
end
在您的Survey
模型中,添加此
serialize :responses, Hash