如何在Heroku上使用hstore

3
根据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"附近或附近的语法错误 LINE 1: CREATE EXTENSION hstore ^ :创建扩展名hstore

你使用的是哪个Postgres版本?CREATE EXTENSION是在9.0中引入的,也许你正在使用旧版本? - user330315
在我的本地开发机上,我运行的是9.1.4版本,它可以很好地工作。只有在Heroku上我才遇到了问题。 - vince
那么在Heroku上的版本是什么? - user330315
不确定如何在Heroku上检查Postgres的版本,但根据https://postgres.heroku.com/blog/past/2012/4/26/heroku_postgres_development_plan/,我认为它运行的是9.1版本。 - vince
heroku pg:info === HEROKU_POSTGRESQL_NAVY 计划:Dev 状态:可用 连接数:1 PG 版本:9.1.3 - vince
2个回答

3

2

我认为您希望将迁移拆分为两个:一个用于添加hstore,另一个用于使用它;

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

  def self.down
    execute "DROP EXTENSION hstore"
  end
end

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接