gpt4 book ai didi

ruby-on-rails - 未定义的方法 "each_pair"运行数据库迁移时出错

转载 作者:行者123 更新时间:2023-12-04 07:29:33 27 4
gpt4 key购买 nike

这里是错误:

迁移代码:

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 更改了它正在覆盖的方法的签名。

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

关于ruby-on-rails - 未定义的方法 "each_pair"运行数据库迁移时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29326589/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com