2012-06-26 23 views
3

根據https://postgres.heroku.com/blog/past/2012/4/26/heroku_postgres_development_plan/我做了「heroku addons:add heroku-postgresql:dev」。但是,當我做如何在Heroku上使用hstore

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耙分貝:遷移」我得到這個錯誤:

PG ::錯誤:錯誤:語法錯誤或接近「擴展」 LINE 1:創建EXTENSION hstore^ :CREATE EXTENSION hstore

+0

您正在使用哪個Postgres版本? 'CREATE EXTENSION'在9.0中引入,也許你使用的是舊版本? –

+0

我在本地開發機器上運行9.1.4,它工作正常。只有在heroku上我有問題 – sthapit

+0

那麼heroku上的版本是什麼? –

回答

2

我想你想拆分你的遷移,一個添加hstore,另一個使用它;

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

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

啓用擴展,您的用戶遷移將只添加任何字段,然後使用hstore在您想要的列上。