railsでアプリを開発しており、herokuへのデプロイを試みているのですが、"heroku run rails db:migrate"をすると以下エラーが出ます。
rails aborted! LoadError: Error loading the 'postgresql' Active Record adapter. Missing a gem it depends on? pg is not part of the bundle. Add it to your Gemfile.
ここまでの流れ
・開発環境でmysqlを使用し、本番ではpostgesqlを使用するため、gem.fileには"pg"を記載
group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] # Use mysql as the database for Active Record gem 'mysql2', '>= 0.4.4' gem 'better_errors' gem 'rubocop', require: false gem 'binding_of_caller' gem 'factory_bot_rails' gem 'pry-rails' gem 'rspec-rails' end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '~> 3.2' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' gem 'pg' end
・bundle install --without productionを実行
・config/datebase.ymlの設定
default: &default adapter: mysql2 encoding: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: socket: /tmp/mysql.sock development: <<: *default database: アプリ名_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: アプリ名_test production: <<: *default database: アプリ名_production username: アプリ名 password: <%= ENV['アプリ名_DATABASE_PASSWORD'] %> adapter: postgresql encoding: unicode pool: 5
・config/environments/production.rbの設定
config.assets.compile = true
・git push heroku main
・heroku run rails db:migrate
そして下記エラー
rails aborted! LoadError: Error loading the 'postgresql' Active Record adapter. Missing a gem it depends on? pg is not part of the bundle. Add it to your Gemfile. /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:4:in `<main>' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /app/vendor/bundle/ruby/3.0.0/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:35:in `require' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/connection_specification.rb:169:in `spec' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1058:in `establish_connection' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_handling.rb:51:in `establish_connection' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/railtie.rb:201:in `block (2 levels) in <class:Railtie>' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:71:in `class_eval' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:51:in `each' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/base.rb:327:in `<module:ActiveRecord>' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/base.rb:27:in `<main>' /6.0.4.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /app/vendor/bundle/ruby/3.0.0/gems/railties-6.0.4.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' /app/vendor/bundle/ruby/3.0.0/gems/railties-6.0.4.1/lib/rails/command.rb:48:in `invoke' /app/vendor/bundle/ruby/3.0.0/gems/railties-6.0.4.1/lib/rails/commands.rb:18:in `<main>' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /app/bin/rails:4:in `<main>' Caused by: Gem::LoadError: pg is not part of the bundle. Add it to your Gemfile. /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:4:in `<main>' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-`establish_connection' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_handling.rb:51:in `establish_connection' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/railtie.rb:201:in `block (2 levels) in <class:Railtie>' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:71:in `class_eval' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:51:in `each' /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.0.4.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/base.rb:327:in `<module:ActiveRecord>' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/base.rb:27:in `<main>' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /app/vendor/bundle/ruby/3.0.0/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:35:in `require' /app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.0.4.1/lib/active_record/railties/databases.rake:19:in `block (2 levels) in <main>' /app/vendor/bundle/ruby/3.0.0/gems/railties-6.0.4.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /app/vendor/bundle/ruby/3.0.0/gems/railties-6.0.4.1/lib/rails/commands/rake/rake_command.rb:20:in `perform' /app/vendor/bundle/ruby/3.0.0/gems/railties-6.0.4.1/lib/rails/command.rb:48:in `invoke' /app/vendor/bundle/ruby/3.0.0/gems/railties-6.0.4.1/lib/rails/commands.rb:18:in `<main>' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' /app/bin/rails:4:in `<main>'
試したこと
・エラー文にvendor/bundleの記述があり、gitignoreにvendor/bundleを記載しているのでおかしいなと思い、git rm --cached -r vendor/bundleをしましたが、no such fileとなりました。
・gem install pgでインストールし、再度bundle install
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2021/12/03 03:17