【问题标题】:How to use hstore on Heroku如何在 Heroku 上使用 hstore
【发布时间】:2012-06-27 13:09:12
【问题描述】:

根据https://postgres.heroku.com/blog/past/2012/4/26/heroku_postgres_development_plan/,我做了“heroku addons:add heroku-postgresql:dev”。但是当我这样做时

class CreateUsers < ActiveRecord::Migration 
  def up 
    create_table :users do |t| 
      execute "CREATE EXTENSION hstore" 
      t.hstore :access 
    end 
  end 

  def down 
    drop_table :users 
      execute "DROP EXTENSION hstore" 
    end 
  end
end

然后“heroku run rake db:migrate”我得到这个错误:

PG::Error: ERROR: "EXTENSION" 处或附近的语法错误 第 1 行:创建扩展 hstore ^ : 创建扩展 hstore

【问题讨论】:

  • 您使用的是哪个 Postgres 版本? CREATE EXTENSION是9.0引入的,可能你用的是旧版本?
  • 在我的本地开发机器上,我正在运行 9.1.4,它工作正常。我只有在 heroku 上遇到问题
  • 那么heroku上的版本是什么?
  • 不确定如何在 heroku 上检查 postgres 的版本,但根据 postgres.heroku.com/blog/past/2012/4/26/… 我认为它运行 9.1
  • heroku pg:info === HEROKU_POSTGRESQL_NAVY 计划:开发状态:可用连接数:1 PG 版本:9.1.3

标签: ruby-on-rails-3 postgresql heroku hstore


【解决方案1】:

终于让它工作了。事实证明,我需要按照https://devcenter.heroku.com/articles/heroku-postgres-dev-plan

使用 heroku pg:promote 来“提升”数据库

【讨论】:

    【解决方案2】:

    我认为您想拆分迁移,一个用于添加 hstore,另一个用于使用它;

    class SetupHStore < ActiveRecord::Migration 
      def self.up
        execute "CREATE EXTENSION hstore"
      end
    
      def self.down
        execute "DROP EXTENSION hstore"
      end
    end
    

    启用扩展,您的用户迁移将只添加任何字段,然后在您想要的任何列上使用 hstore。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-06
      • 2015-09-09
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      • 2020-01-19
      • 2017-08-09
      • 2016-12-08
      相关资源
      最近更新 更多