运行数据库迁移时未定义的方法“each_pair”错误

时间:2015-03-29 07:09:26

标签: ruby-on-rails activerecord dbmigrate

这是错误:

迁移代码:

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

作为旁注,如果我删除“Create_table”调用,它不会失败。

运行rake db:migrate后,我收到此错误消息:

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'

怎么可能解决这个问题?我正在使用“pg”gem,我的适配器是postgresql。

完整跟踪错误:

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'

1 个答案:

答案 0 :(得分:8)

这取决于您正在使用的schema_plus gem:rails 4.2.1更改了它覆盖的方法的签名。

主分支上有一个fix,但这是won't be backported到gem的1.x系列,它不支持rails 4.2之后的版本。但是,您可以使用当前的2.0.0预发行版本。