运行 数据库迁移时未定义的方法 "each_pair" 出错
Undefined Method "each_pair" Error when running DB Migrate
这里是错误:
迁移代码:
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'
这取决于您正在使用的 schema_plus gem:rails 4.2.1 更改了它正在覆盖的方法的签名。
gem的1.x系列有一个fix on the master branch, however this won't be backported,不支持rails4.2以后的版本。但是,您可以使用当前的 2.0.0 预发布版本。
这里是错误:
迁移代码:
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'
这取决于您正在使用的 schema_plus gem:rails 4.2.1 更改了它正在覆盖的方法的签名。
gem的1.x系列有一个fix on the master branch, however this won't be backported,不支持rails4.2以后的版本。但是,您可以使用当前的 2.0.0 预发布版本。