I am trying to use postgresql with Ruby on Rails on Heroku but got an error
我试图在Heroku上使用带Ruby on Rails的postgresql但是出错了
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.
请帮我解决这个问题。
3 个解决方案
#1
8
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 group之外添加gem,并删除其他数据库适配器,例如sqlite。
As a side note, you may also want to add the rails_12factor
gem as suggested by Heroku.
作为旁注,您可能还想按照Heroku的建议添加rails_12factor gem。
#2
12
This worked for me
这对我有用
gem 'pg', '~> 0.20'
宝石'pg','〜> 0.20'
Thanks to Piers C
感谢Piers C.
Got this answer from
得到了这个答案
Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE
Heroku和Rails:Postgres的Gem加载错误,但它在GEMFILE中指定
#3
6
Add pg in gemfile
在gemfile中添加pg
gem 'pg', '~> 0.20'
then bundle update & commit Gemfile & Gemfile.lock to heroku.
simple include like gem 'pg' will not work.
然后捆绑更新并将Gemfile和Gemfile.lock提交到heroku。简单包括像宝石'pg'将无法正常工作。
#1
8
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 group之外添加gem,并删除其他数据库适配器,例如sqlite。
As a side note, you may also want to add the rails_12factor
gem as suggested by Heroku.
作为旁注,您可能还想按照Heroku的建议添加rails_12factor gem。
#2
12
This worked for me
这对我有用
gem 'pg', '~> 0.20'
宝石'pg','〜> 0.20'
Thanks to Piers C
感谢Piers C.
Got this answer from
得到了这个答案
Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE
Heroku和Rails:Postgres的Gem加载错误,但它在GEMFILE中指定
#3
6
Add pg in gemfile
在gemfile中添加pg
gem 'pg', '~> 0.20'
then bundle update & commit Gemfile & Gemfile.lock to heroku.
simple include like gem 'pg' will not work.
然后捆绑更新并将Gemfile和Gemfile.lock提交到heroku。简单包括像宝石'pg'将无法正常工作。