I try to migrate my app from Rails 4 to Rails 5 Here is my migration:
class AddRevealedIdsToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :revealed_ids, :text, default: []
end
end
And model:
serialize :revealed_ids
It worked perfectly in Rails 4, now I have an error:
== 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'
how to solve?
As temporary solution I serialize it manually.
add_column :users, :revealed_ids, :text, default: [].to_yaml
Opened an issue in Rails repository.
You can try adding array:true
to your migration.
add_column :users, :revealed_ids, :text, default: [], array:true
That fixed it for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With