【问题标题】:Cannot add hstore column to multitenant rails 4 applicaiton (postgres schema based)无法将 hstore 列添加到多租户 Rails 4 应用程序(基于 postgres 模式)
【发布时间】:2014-06-06 19:56:22
【问题描述】:

我正在尝试将 hstore 添加到我的应用程序中。但是我收到一条错误消息,告诉我 hstore 不存在。

PG::UndefinedObject: ERROR:  type "hstore" does not exist
LINE 1: ALTER TABLE "people" ADD COLUMN "custom_fields" hstore

这是我的迁移:

class AddCustomFieldsToPeople < ActiveRecord::Migration
  def up
    add_column :people, :custom_fields, :hstore
  end

  def down
    remove_column :people, :custom_fields
  end
end

根据this SO answer,我不必在每个架构上创建 hstore 扩展,而只需将其添加到例如公共架构。

除了添加 postgres 扩展来让 hstore 工作之外,我还需要做些什么吗?

感谢任何帮助。 :)

【问题讨论】:

  • 尝试:\c ;创建扩展 hstore;
  • 我已经添加了hstore。所以我得到错误:'扩展“hstore”已经存在':-/
  • 你的 PostgreSQL && Rails 是什么版本?
  • Postgres 9.3 版和 Rails 4.0.2
  • 在 mac osx 上使用 Postgres 应用程序

标签: ruby-on-rails postgresql ruby-on-rails-4 hstore


【解决方案1】:

用这个和 rake 生成一个迁移:

class AddHstore < ActiveRecord::Migration  
  def up
    enable_extension :hstore
  end

  def down
    disable_extension :hstore
  end
end    

由于您已经有迁移待定,请使用 rake db:migrate:up VERSION=

【讨论】:

    猜你喜欢
    • 2020-06-26
    • 2023-03-16
    • 2017-11-15
    • 2013-03-24
    • 2020-02-02
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多