【问题标题】:Rails 3.1 - Pushing to Heroku - Errors installing postgres adapter?Rails 3.1 - 推送到 Heroku - 安装 postgres 适配器时出错?
【发布时间】:2011-11-09 22:24:51
【问题描述】:

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

heroku rake db:迁移

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 来让这个东西工作?

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

【问题讨论】:

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


【解决方案1】:

选项 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

【讨论】:

  • 很酷,是的,我最终做了第二个。如果在本地维护 postgresql 变得很烦人,那么也许我会放弃它,希望我不会后悔那个决定。
  • 给你的README添加评论。
【解决方案2】:

你肯定需要 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 的组中,然后将 bundle install --without production 放在本地。

【讨论】:

    【解决方案3】:

    更多最新信息:它与本地不同版本的 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 时,工作就像一个魅力

    【讨论】:

      猜你喜欢
      • 2011-12-13
      • 2012-09-18
      • 2018-07-18
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多