LoginSignup
5
2

More than 1 year has passed since last update.

「heroku run rails db:migrate:reset」時に発生したエラーを対処

Posted at

状況

Heroku上のRailsアプリDB(PostgreSQL)を修正しようとheroku run rails db:migrate:resetを実行したところ下記のエラーが発生しました。

rails aborted!
ActiveRecord::ConnectionNotEstablished: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket

Caused by:
PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?

環境

  • macOS Big Sur 11.6.1
  • Rails 6.1.2
  • PostgreSQL 14.0

改善

エラー文の内容では、postgresqlのファイルまたはディレクトリが存在しないとのこと。
何らかの理由で消えてしまっているようなので下記のPostgreSQLのアドオンを実行。

$ heroku addons:create heroku-postgresql

再度、マイグレートを実行して解決出来ました。

$ heroku run rails db:migrate

まとめ

デプロイ時にはcreate出来ており問題なく使えていました。
ローカル側のエラーを疑ってしまい解決まで時間を要してしましたが、Heroku上でも起こり得ることを学びました。
また、Heroku上のアプリページにあるConfigure Add-onsというページでもDBの確認が可能です。

参考

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2