问题
I am a Rails beginner and i see some issue while deploying to Heroku.
Earlier i used SQLite3, later when i understood that i needed postgresql i installed the same and work on local machine.
One deployment went fine after migrating from sqlite to postgresql. Now i see some issue.
Heroku logs, Gem file and Database.yml details are as below.
Can some one help me in this please.
Advance Thanks...!!!
Part of Gem file:
group :development, :test do
gem 'pg', '~> 1.0.0'
gem 'rails_12factor'
#gem 'sqlite3'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :production do
gem 'pg', '~> 1.0.0'
gem 'rails_12factor'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Database.yml:
development:
adapter: postgresql
encoding: unicode
database: database_postgresql
pool: 5
username: postgres
password: secret
test:
adapter: postgresql
encoding: unicode
database: database_postgresql_test
pool: 5
username: postgres
password: secret
production:
adapter: postgresql
encoding: unicode
database: database_postgresql
pool: 5
username: postgres
password: secret
Part of Heroku logs.
remote: -----> Installing node-v6.11.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: Yarn executable was not detected in the system.
remote: Download Yarn at https://yarnpkg.com/en/docs/install
remote: I, [2018-01-15T13:38:08.180450 #590] INFO -- : Writing /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/public/assets/jumbotron--032aba6cd1415006731040523573e7138c703aedc6d1f46b3622cbe4c9feec27.jpg
remote: rake aborted!
remote: Gem::LoadError: 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).
remote: /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:188:in `rescue in spec'
remote: /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
remote: /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
remote: Tasks: TOP => assets:precompile
remote: (See full trace by running task with --trace)
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to damp-beyond-28813.
回答1:
If you have recently deployed your app to Heroku and in your attempt have been getting the "App crashed" error when you go to the Heroku app link, but everything else seems to be in order, it's most likely due to a new release of the 'pg' gem
. Postgres has released a new version of its gem which seems not fully compatible yet, so in your Gemfile under group production
change the line:
gem 'pg'
OR
gem 'pg', '~> 1.0.0'
to
gem 'pg', '~> 0.11'
OR
gem 'pg', '~> 0.20.0'
Note: the tilde sign before the >
, that's not a dash
Once you make this update in your group production of your Gemfile, ensure you run bundle install --without production
(to update Gemfile.lock file), do a git add/commit cycle, then re-deploy to Heroku.
For Good Practice
Use pg gem
one time without :group
because your database is same for both development
& production!
来源:https://stackoverflow.com/questions/48264765/heroku-with-rails-5-error-gemloaderror-specified-postgresql-for-database-ad