質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

Q&A

解決済

1回答

889閲覧

herokuへのデプロイで "heroku run rails db:migrate"をするとエラーになる

退会済みユーザー

退会済みユーザー

総合スコア0

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

0グッド

0クリップ

投稿2021/12/02 16:42

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

なぜgroup :development内にgem 'pg'を書いているのでしょうか。本番環境はproductionかと思います。

投稿2021/12/02 23:10

maisumakun

総合スコア145183

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2021/12/03 03:17

見落としておりました。 ありがとうございます。無事デプロイできました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問