Search code examples
ruby-on-railsactiverecorddbmigrate

Undefined Method "each_pair" Error when running DB Migrate


here is the error:

Migration Code:

class Test < ActiveRecord::Migration
  def change
    create_table :test do |t|
    end
  end
end

As a side note, it does not fail if i remove the "Create_table" call.

Upon running rake db:migrate, I get this error mesage:

StandardError: An error has occurred, this and all later migrations canceled:

undefined method `each_pair' for []:Array/Users/m/Apps/stream-web/db/migrate/20150329070040_test.rb:3:in `change'
NoMethodError: undefined method `each_pair' for []:Array
/Users/m/Apps/stream-web/db/migrate/20150329070040_test.rb:3:in `change'

How might one go about resolving this? I am using the "pg" gem and my adapter is postgresql.

Full trace error:

undefined method `each_pair' for []:Array/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:216:in `create_table'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/schema_plus-1.8.5/lib/schema_plus/active_record/connection_adapters/schema_statements.rb:39:in `create_table_with_schema_plus'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:662:in `block in method_missing'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `block in say_with_time'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `say_with_time'
/Users/mingyeowng/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:652:in `method_missing'
/Users/mingyeowng/Apps/stream-web/db/migrate/20150329070040_test.rb:3:in `change'

Solution

  • This is down to the schema_plus gem you are using: rails 4.2.1 changed the signature of a method it was overriding.

    There is a fix on the master branch, however this won't be backported to the 1.x series of the gem, which doesn't support versions after rails 4.2. You can however use the current 2.0.0 pre-release versions.