Rails5 migration: can't quote Array

15,565

Solution 1

You can try adding array:true to your migration.

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

That fixed it for me.

Solution 2

As temporary solution I serialize it manually.

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

Opened an issue in Rails repository.

Share:
15,565
Mikhail Chuprynski
Author by

Mikhail Chuprynski

Developer in the past, now working with DevOps projects

Updated on July 26, 2022

Comments

  • Mikhail Chuprynski
    Mikhail Chuprynski almost 2 years

    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?