“未加载 postgresql gem"在 Heroku 上部署 Ruby on Rails 应用程序时出错
问题描述:
我正在尝试在 Heroku 上将 postgresql 与 Ruby on Rails 结合使用,但出现错误
I am trying to use postgresql with Ruby on Rails on Heroku but got an error
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)
请帮我解决这个问题.
答
在你的 Gemfile
group :production do
gem 'pg'
end
然后运行 bundle install
并尝试在 Heroku 上部署.
Then run bundle install
and try to deploy on Heroku.
如果您想在所有环境中使用 PostgreSQL 而不仅仅是在 production
(推荐)中,请在 :production
组之外添加 gem 并删除其他数据库适配器,例如 sqlite.
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
.
作为旁注,您可能还想添加 rails_12factor
Heroku 建议的 gem.
As a side note, you may also want to add the rails_12factor
gem as suggested by Heroku.