2016-08-15 24 views
1

我嘗試遷移從Rails的4至導軌5 這裏我的應用程序是我的移民:Rails5遷移:不能引用數組

class AddRevealedIdsToUser < ActiveRecord::Migration[5.0] 
    def change 
    add_column :users, :revealed_ids, :text, default: [] 
    end 
end 

和型號:

serialize :revealed_ids 

它的工作完美Rails 4,現在我有一個錯誤:

== 20160416214334 AddRevealedIdsToUser: migrating ============================= 
-- add_column(:users, :revealed_ids, :text, {:default=>[]}) 
rails aborted! 
StandardError: An error has occurred, this and all later migrations canceled: 

can't quote Array 
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/quoting.rb:177:in `_quote' 
/usr/local/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/quoting.rb:96:in `_quote' 

怎麼解決?

回答

2

您可以嘗試將array:true添加到您的遷移中。

add_column :users, :revealed_ids, :text, default: [], array:true 

這就爲我修好了。

13

作爲臨時解決方案,我手動序列化它。

add_column :users, :revealed_ids, :text, default: [].to_yaml 

在Rails存儲庫中打開了一個問題。

+0

這是正確的答案 – user2167582

+0

@mikhail什麼是問題編號? –