Mik*_*ski 3 ruby-on-rails ruby-on-rails-5
我尝试将我的应用程序从Rails 4迁移到Rails 5这是我的迁移:
class AddRevealedIdsToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :revealed_ids, :text, default: []
end
end
Run Code Online (Sandbox Code Playgroud)
和型号:
serialize :revealed_ids
Run Code Online (Sandbox Code Playgroud)
它在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'
Run Code Online (Sandbox Code Playgroud)
怎么解决?
Mik*_*ski 26
作为临时解决方案,我手动序列化它.
add_column :users, :revealed_ids, :text, default: [].to_yaml
Run Code Online (Sandbox Code Playgroud)
在Rails存储库中打开了一个问题.
您可以尝试添加array:true到迁移中。
add_column :users, :revealed_ids, :text, default: [], array:true
Run Code Online (Sandbox Code Playgroud)
这为我解决了。
| 归档时间: |
|
| 查看次数: |
9133 次 |
| 最近记录: |