Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails5 migration: can't quote Array

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?

like image 382
Mikhail Chuprynski Avatar asked Aug 15 '16 11:08

Mikhail Chuprynski


2 Answers

As temporary solution I serialize it manually.

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

Opened an issue in Rails repository.

like image 60
Mikhail Chuprynski Avatar answered Sep 28 '22 13:09

Mikhail Chuprynski


You can try adding array:true to your migration.

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

That fixed it for me.

like image 22
Augusto Samamé Barrientos Avatar answered Sep 28 '22 15:09

Augusto Samamé Barrientos