【问题标题】:Heroku error when launch rails3.1 app missing postgres gem启动 rails3.1 应用程序缺少 postgres gem 时出现 Heroku 错误
【发布时间】:2011-09-18 15:09:45
【问题描述】:

我正在尝试部署到 heroku。

Rails 3.1.0.rc4,

我从 Heroku 日志中收到以下错误:

Starting process with command: `thin -p 48902 -e production -R /home/heroku_rack/heroku.ru start`
2011-06-20T11:25:44+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection': Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.) (RuntimeError)

我尝试安装 activerecord-postgresql-adapter,但随后出现此错误:

Could not find gem 'activerecord-postgresql-adapter (>= 0)' in any of the gem sources listed in your Gemfile.

所以我尝试将它添加到我的 gem 文件中

宝石'pg'

产生了这个错误:

Installing pg (0.11.0) with native extensions /Users/imac/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

有什么想法吗?

【问题讨论】:

  • 当我在 database.yml 中将适配器设置为 postgres 而不是 postgresql 时,我在本地看到了该错误,但由于 Heroku 在部署时重写了 database.yml,我认为这不是问题所在。您是否有机会使用 Cedar 堆栈?如果您没有在本地安装 Postgresql,那么这将解释最后一个错误,因为您需要安装它才能在本地安装 gem。

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


【解决方案1】:

您不必在本地安装 Postgres。在您的 Gemfile 中,按照 johnny-grass 的建议,将 'pg' 放入 group :production,然后在运行 bundle 时,只需指定 --without production,如下所示:

bundle --without production

不幸的是,您在运行 bundler 时必须记住这个参数,但至少您不必在本地安装和维护 postgres。

请注意,Heroku “强烈建议不要”使用 sqlite,说“您的生产和开发环境应尽可能接近相同”http://devcenter.heroku.com/articles/rails3

【讨论】:

  • 我没有安装 postgress 或使用 bundle --without production,将 gem 安装在我的本地机器上。
  • @Chris 详细说明了您是如何做到这一点的?
【解决方案2】:

您的计算机上是否安装了PostgreSQL?如果你不先安装它,然后安装 pg gem。

# gemfile
group :production do
  gem 'therubyracer-heroku', '0.8.1.pre3' # you will need this too
  gem 'pg'
end

【讨论】:

  • 我的系统上没有 PostgreSQL。我会听从你的指示,并希望一切顺利。感谢您的建议。
  • this article 的帮助下,以下内容在 Ubuntu 上为我工作:sudo apt-get install postgresql,然后是 sudo apt-get install libpq-dev。此外,therubyracer 0.9.4 似乎在 Heroku 上编译得很好——我不需要 'therubyracer-heroku'
【解决方案3】:

我在这个 Heroku article 中找到了解决方案。

正如 Jared 所说,他们建议为 postgresql 创建一个不同的组。

【讨论】:

    猜你喜欢
    • 2021-03-11
    • 2019-09-07
    • 1970-01-01
    • 2021-03-10
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 2017-05-07
    相关资源
    最近更新 更多