Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Heroku Gem::LoadError:指定';postgresql';用于数据库适配器,但未加载gem。添加“gem';pg';`到你的档案_Heroku_Ruby On Rails 4 - Fatal编程技术网

Heroku Gem::LoadError:指定';postgresql';用于数据库适配器,但未加载gem。添加“gem';pg';`到你的档案

Heroku Gem::LoadError:指定';postgresql';用于数据库适配器,但未加载gem。添加“gem';pg';`到你的档案,heroku,ruby-on-rails-4,Heroku,Ruby On Rails 4,我不熟悉Rails。这个应用程序在我的本地机器上运行良好,部署起来没有任何问题。但是当我运行heroku run rake db:migrate时,我得到了以下错误: Running `rake db:migrate` attached to terminal... up, run.1269 rake aborted! Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. A

我不熟悉Rails。这个应用程序在我的本地机器上运行良好,部署起来没有任何问题。但是当我运行heroku run rake db:migrate时,我得到了以下错误:

Running `rake db:migrate` attached to terminal... up, run.1269
rake aborted!
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile.

将此行添加到
:production
组内的
GEM文件中(如果没有,请添加一行)

从错误本身可以清楚地看出,gem
pg
需要添加到您的
Gemfile
。您可能只是简单地添加了它,但您需要为您的开发和生产机器添加gem,因为Heroku应用程序是您系统的生产机器,而您的localhost是开发机器

您的
Gemfile
应该如下所示:

source 'https://rubygems.org'
ruby '2.0.0'


gem 'rails', '4.0.0'
gem 'bootstrap-sass', '2.3.2.0'
gem 'bcrypt-ruby', '3.0.0'
gem 'faker', '1.1.2'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'

end
group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor'
end

简单地将gem'pg'添加到gem文件对我来说不起作用

这对我有用

宝石'pg','~>0.20'

我从你那里得到了这个答案

多亏了皮尔斯C


是的,gem'rails\u 12factor'在查看Heroku的日志以获取错误消息时很有帮助。

我在升级gitlab时遇到了错误。我执行了错误的命令,说
sudo-u git-H bundle安装--不带postgres开发测试--部署
,而不是
sudo-u git-H bundle安装--不带mysql开发测试--部署

简单执行

sudo-u git-H bundle安装——用postgres
为我做的,可能是你的情况

bundle安装——使用postgres
并在db迁移之后,
heroku运行rakedb:migrate

您还可以通过将rails升级到>=5.1.5版本来修复它


参考资料:

我正在使用ruby 2.3.8。如果您无法解决此问题,则问题可能与您尝试使用的pg版本有关。将
gem'pg'
替换为
gem'pg',“~>0.21'
对我来说效果很好。另外,这是我的database.yml文件:

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5
development:
  <<: *default
  database: <%= ENV['DB_NAME'] %>
  host: <%= ENV['DB_HOST'] %>
  username: <%= ENV['DB_USERNAME'] %>
  password: <%= ENV['DB_PASSWORD'] %>
  reconnect: true
test:
  <<: *default
  database: <%= ENV['POSTGRES_DB'] %>
  password: <%= ENV['POSTGRES_PASSWORD'] %>
  username: <%= ENV['POSTGRES_USER'] %>
  host: <%= ENV['POSTGRES_HOST'] %>
  port: <%= ENV['POSTGRES_PORT'] %>
  min_messages: notice
production:
  <<: *default
  host: <%= ENV['DB_HOST'] %>
  database: <%= ENV['DB'] %>
  username: <%= ENV['DB_USERNAME'] %>
  password: <%= ENV['DB_PASSWORD'] %>
default:&default
适配器:postgresql
编码:unicode
#有关连接池的详细信息,请参阅rails配置指南
# http://guides.rubyonrails.org/configuring.html#database-汇集
游泳池:5
发展:

可能是@SimoneCarletti的副本你提到的帖子是在我之后发布的。我知道。几个小时前我遇到了同样的问题,我选择了答案最好的一个,并将其他的标记为重复,这样新用户就不会感到困惑。不经意间,我选的那一个比你的年轻。评论由SO自动发布。如果您使用Mac OS X,请不要忘记使用
brew安装postgresql
安装postgresql。我在我的gem文件中
group:production
下有
gem'pg'
。但我仍然得到了错误。我在OSX上,我已经完成了
brew安装postgresql
。有什么线索吗?@UniSoundWaterloo我也有同样的问题,有什么线索吗?我做了一个新的构建,它工作正常。我不知道为什么。@UniSoundWaterloo在花了太多时间后,尝试使用postgres进行捆绑安装--
,这对我来说是一种拯救。在更新到刚刚发布的1.0之后,这种情况再次发生在我身上。仍然有效!
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5
development:
  <<: *default
  database: <%= ENV['DB_NAME'] %>
  host: <%= ENV['DB_HOST'] %>
  username: <%= ENV['DB_USERNAME'] %>
  password: <%= ENV['DB_PASSWORD'] %>
  reconnect: true
test:
  <<: *default
  database: <%= ENV['POSTGRES_DB'] %>
  password: <%= ENV['POSTGRES_PASSWORD'] %>
  username: <%= ENV['POSTGRES_USER'] %>
  host: <%= ENV['POSTGRES_HOST'] %>
  port: <%= ENV['POSTGRES_PORT'] %>
  min_messages: notice
production:
  <<: *default
  host: <%= ENV['DB_HOST'] %>
  database: <%= ENV['DB'] %>
  username: <%= ENV['DB_USERNAME'] %>
  password: <%= ENV['DB_PASSWORD'] %>
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use postgresql as the database for Active Record
# Adding pg gem for postgres
gem 'pg', '~> 0.21'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more:
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end