简体   繁体   English

在 Heroku 上部署 Ruby on Rails 应用程序时出现“未加载 postgresql gem”错误

[英]"postgresql gem is not loaded" error deploying a Ruby on Rails application on Heroku

I am trying to use postgresql with Ruby on Rails on Heroku but got an error我正在尝试在Heroku上将postgresqlRuby on Rails一起使用,但出现错误

Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

Please help me to solve this issue.请帮我解决这个问题。

This worked for me这对我有用

gem 'pg', '~> 0.20'

Thanks to Piers C感谢皮尔斯 C

Got this answer from得到了这个答案

Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE Heroku 和 Rails:Postgres 的 Gem 加载错误,但它在 GEMFILE 中指定

Add pg in gemfile在 gemfile 中添加 pg

 gem 'pg', '~> 0.20'

then bundle update & commit Gemfile & Gemfile.lock to heroku.然后捆绑更新并将 Gemfile 和 Gemfile.lock 提交到 heroku。
simple include like gem 'pg' will not work.像 gem 'pg' 这样的简单包含将不起作用。

In your Gemfile在你的Gemfile

group :production do
  gem 'pg'
end

Then run bundle install and try to deploy on Heroku.然后运行bundle install并尝试在 Heroku 上部署。

If you want to use PostgreSQL on all environments and not only in production (recommended) add the gem outside the :production group and remove other database adapters such as sqlite .如果您想在所有环境中使用 PostgreSQL 而不仅仅是在production (推荐)在:production组之外添加 gem 并删除其他数据库适配器,例如sqlite

As a side note, you may also want to add the rails_12factor gem as suggested by Heroku.作为旁注,您可能还想按照 Heroku 的建议添加rails_12factor gem。

我将以下版本添加到我的 gemfile 中,它已解决。

gem "pg", "~> 0.18"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM