2011-09-04 68 views
38

我剛剛升級到Rails 3.1,我嘗試部署到Heroku的第一個應用程序遇到了與Postgres適配器相關的問題。我能夠在應用程序推送到Heroku的,但後來當我嘗試遷移數據庫,會出現以下錯誤:Rails 3.1 - 推向Heroku - 錯誤安裝postgres適配器?

Heroku的耙分貝:遷移

rake aborted! 
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` 
(pg is not part of the bundle. Add it to Gemfile.) 
Tasks: TOP => db:migrate => db:load_config 
(See full trace by running task with --trace) 

,當我嘗試了建議安裝,我得到:

ERROR: Could not find a valid gem 'activerecord-postgresql-adapter' (>= 0) in any repository 
ERROR: Possible alternatives: activerecord-postgis-adapter, activerecord-jdbcpostgresql-adapter, activerecord-postgresql-cursors, activerecord-jdbcmysql-adapter, activerecord-jdbcmssql-adapter 

這似乎已經有點怪,所以我應該安裝什麼確切的寶石,如果不是他們說什麼,我應該安裝讓這件事的工作?

當我嘗試安裝寶石PG我得到:

Building native extensions. This could take a while... 
ERROR: Error installing pg: 
     ERROR: Failed to build gem native extension. 

/Users/jerometufte/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb 
checking for pg_config... no 
No pg_config... trying anyway. If building fails, please try again with 
--with-pg-config=/path/to/pg_config 
checking for libpq-fe.h... no 
Can't find the 'libpq-fe.h header 
*** extconf.rb failed *** 
Could not create Makefile due to some reason, probably lack of 
necessary libraries and/or headers. Check the mkmf.log file for more 
details. You may need configuration options. 

Provided configuration options: 
    --with-opt-dir 
    ... 

我使用sqlite3的當前。任何幫助非常感謝,這讓我感到困惑。

+0

如何設置的PostgreSQL爲Rails和Heroku的 HTTP:// robdodson .me/blog/2012/04/27/how-to-setup-postgresql-for-rails-and-heroku/ –

回答

41

選項1:

添加pgGemfile但跳過嘗試在本地安裝它。

$ cat Gemfile 
... 
group :production do 
    # gems specifically for Heroku go here 
    gem "pg" 
end 

# Skip attempting to install the pg gem 
$ bundle install --without production 

選項2(於Debian/Ubuntu):

添加pgGemfile但首先安裝的先決條件。

$ cat Gemfile 
... 
group :production do 
    # gems specifically for Heroku go here 
    gem "pg" 
end 

# Install the pg gem's dependencies first 
$ sudo apt-get install libpq-dev 
# Then install the pg gem along with all the other gems 
$ bundle install 
+0

很酷,我最終做了第二個。如果在本地維護postgresql變得煩人,那麼也許我會拋棄它,希望我不會後悔這個決定。 – tuddy

+0

給你的'README'添加註釋。 – yfeldblum

4

你絕對需要在Gemfile for Heroku中使用pg。

關於您在本地收到的錯誤:請確保您安裝了postgres,運行gem install pq -- --with-pg-config=[path to wherever your pg-config binary is],然後進行捆綁安裝。或者,如果您的本地數據庫工作正常(無論是因爲您使用的是sqlite還是postgres-pr),您可以將gem 'pg'行放入您的Gemfile中的一個名爲production的組中,然後bundle install --without production在本地。

1

更新最新信息:它與本地不同版本的pg gem有關。

我已經在一個生產組(我在本地運行sqllite)pg,但Heroku仍在嘔吐。

問題走了我新的Rails 3.1的應用程序,當我:

rm Gemfile.lock 
touch Gemfile 
bundle install 
git add . 
git commit -am "wiped Gemfile.lock re-ran bundle install" 
git push heroku master 

工作就像一個魅力,當我然後跑heroku run rake db:migrate