【问题标题】:undefined method `hstore' for Active RecordActive Record 的未定义方法“hstore”
【发布时间】:2013-05-11 21:16:47
【问题描述】:

我正在关注 Ryan Bates 在 Railscasts http://railscasts.com/episodes/400-what-s-new-in-rails-4 的第 400 集中对 Rails 4 的预览。他将应用程序设置为使用 postgres(我已经安装)和 hstore 的演示。他创造了一个这样的脚手架

rails g scaffold article name content:text published_on:date tags properties:hstore

在迁移中这样做

execute "create extension hstore"
create_table :articles do |t|
  t.string :name
  t.text :content
  t.date :published_on
  t.string :tags, array: true
  t.hstore :properties
  t.timestamps
end

但是,当我运行此迁移时,我遇到了未定义的方法“hstore”错误。然后我进入我的测试数据库并创建了如下所示的 hstore 扩展(而不是像 Ryan 那样在迁移文件中)

psql rails4test2_development
psql (9.2.3)
Type "help" for help.

rails4test2_development=# CREATE EXTENSION hstore;

但我在运行迁移时遇到了同样的错误。

undefined method `hstore' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition:0x007fa7ee7a9138>/Users/me/Sites/rails4test2/db/migrate/20130511204911_create_articles.rb:9:in `block in change'
/Users/me/Sites/rails4test2/db/migrate/20130511204911_create_articles.rb:4:in `change'

谁能帮我理解为什么这对我不起作用?

【问题讨论】:

  • @GoGoGarrett,我不完全确定您期望的答案类型;快速搜索hstore 列方法或键入以下两个取自Rails 3.2.19Rails 4.2.0beta1 的文件表明该方法在最新的Rails 3 中未定义。

标签: ruby-on-rails postgresql


【解决方案1】:

问题是,即使我安装了 Rails 4 gem,应用程序仍在使用 Rails 3.2,它本身不支持 hstore

【讨论】:

  • 对于可能有同样错误但使用 rails 4 的其他人:使用 psql cli 创建扩展 hstore 时出现同样错误的另一种可能方法;而不是迁移,是在删除并重新创建数据库后忘记重做此命令。
【解决方案2】:

我怀疑这是一个有许多潜在原因的问题。对我们来说,原因是 Seamless_database_pool gem。

https://github.com/bdurand/seamless_database_pool/issues/17

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多