Rails 3.1 - 推送到Heroku - 错误安装postgres适配器?

时间:2011-09-04 00:32:58

标签: postgresql heroku ruby-on-rails-3.1

我刚刚升级到Rails 3.1,我尝试部署到Heroku的第一个应用程序遇到了与Postgres适配器有关的问题。我能够将应用程序推送到heroku但是当我尝试迁移数据库时,我收到以下错误:

heroku rake db:migrate

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

这已经看起来很奇怪...所以我应该安装什么确切的宝石来让这个东西工作,如果不是他们说我应该安装?

当我尝试安装gem 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。非常感谢任何帮助,这让我感到困惑。

3 个答案:

答案 0 :(得分:42)

选项1:

pg添加到Gemfile,但请跳过尝试在本地安装。

$ 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):

pg添加到Gemfile,但请先安装先决条件。

$ 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

答案 1 :(得分:4)

你肯定需要在Heroku的Gemfile中使用pg。

关于您在本地获取的错误:确保安装了postgres,运行gem install pq -- --with-pg-config=[path to wherever your pg-config binary is],然后捆绑安装。

或者,如果您的本地数据库工作正常(因为您使用的是sqlite或postgres-pr),您可以将Gemfile中的gem 'pg'行放在名为production的组中,然后{{1} }本地。

答案 2 :(得分:1)

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

我已经在一个制作组中有pg(我在本地运行sqllite),但是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

时,

就像一个魅力