Ruby on rails NoMethodError:未定义的方法'value'u for#u database';对于#<;阵列>;(第5条)

Ruby on rails NoMethodError:未定义的方法'value'u for#u database';对于#<;阵列>;(第5条),ruby-on-rails,postgresql,rails-migrations,Ruby On Rails,Postgresql,Rails Migrations,我有一个(全新的)Rails 5项目,当我尝试运行迁移时会抛出错误 (我使用PostgreSQL 9.4在Raspberry Pi上运行Ruby 2.2.4,但当我第一次尝试使用SQLite运行迁移时,出现了相同的错误消息。) 到目前为止,我唯一的迁移是非常基本的: class CreateAuthors < ActiveRecord::Migration[5.0] def change create_table :authors do |t| t.string :

我有一个(全新的)Rails 5项目,当我尝试运行迁移时会抛出错误

(我使用PostgreSQL 9.4在Raspberry Pi上运行Ruby 2.2.4,但当我第一次尝试使用SQLite运行迁移时,出现了相同的错误消息。)

到目前为止,我唯一的迁移是非常基本的:

class CreateAuthors < ActiveRecord::Migration[5.0]
  def change
    create_table :authors do |t|
      t.string :username
      t.timestamps
    end
  end
end
Edit:也许值得一提的是,
rakedb:create
运行良好

这是我的
数据库.yml
文件,以防我遗漏了一些东西(我对PostgreSQL非常熟悉)

default:&default
适配器:postgresql
编码:unicode
游泳池:
发展:

从第一行中删除[5.0]

class CreateAuthors结束
从第一行删除[5.0]

重新启动服务器并运行rake db:migrate


也许这会对你有所帮助。

P>我在发展中遇到了同样的问题。我们已经找到了原因

在我的例子中,我添加了一个新的gem“imgurapi”,它将“to_hash”添加到数组对象中

class Array # :nodoc:
  # Skipped code 

  def to_hash # :nodoc:
    inject({}) { |hsh, (k,v)| hsh[k] = v  ; hsh }
  end unless method_defined?(:to_hash)
end
因此,在
gems/activerecord-5.0.0.1/lib/active\u record/connection\u adapters/postgresql/database\u语句中调用代码
exec\u查询(sql,name,binds)
,根据原因将
binds
变量从数组转换为哈希类型,这在这里描述得很好。结果我们出现了错误,因为此转换是意外的

解决方案


找到为数组定义“to_hash”方法的gem,并去掉此定义。祝你好运

我试过了,但它仍然给我同样的错误,[5.0]是由
railsgmodel作者
生成的迁移的一部分;移除它没有什么区别。
default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: gnn_dev
  username: gnn
  password: Lorem123
  host: localhost
  port: 5432
class Array # :nodoc:
  # Skipped code 

  def to_hash # :nodoc:
    inject({}) { |hsh, (k,v)| hsh[k] = v  ; hsh }
  end unless method_defined?(:to_hash)
end