3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

heroku本番環境(production)でデプロイ後の接続エラー対処方法

Posted at

課題が終わると思ったらエラーが、、
データベース接続設定を忘れていたので、忘備録のために。。後学の初心者の為に。。。

webアプリをherokuへデプロイして、アプリを開こうとしたら、エラーの文字が。。

We're sorry, but something went wrong.
If you are the application owner check the logs for more information.

原因は..

Rails側の設定でPostgreSQLを使用するための設定を忘れたのが原因だった。
本来なら以下の手順でしていれば問題なかった。
1.Gemfile
2.config/database.yml

1の最後の行に

Gemfile
group :production do
  gem 'pg', '>= 0.18', '< 2.0'
end

を追加。

$ bundle install --without production

実行。

config/database.yml
production:
  adapter: postgresql
  encoding: unicode
  pool: 5
  database: アプリ名_production
  username: アプリ名
  password:<%= ENV['大文字アプリ名_DATABASE_PASSWORD'] %>

コミットを忘れずに。
$ git add .
$ git commit -m'#'

もう一度デプロイ。
$ git push heroku master

開くか確認。
https://Herokuアプリ名.herokuapp.com/
OKなら、
$ heroku run rails db:migrate
本来この手順ならここで終わりだが。。

私の場合は
最初のデプロイでconfig/database.ymlを設定せずにいたために
PostgreSQLが自動的にインストールされませんでした。

これを解決するには手動でインストール。
$ heroku addons:create heroku-postgresql:hobby-dev

再度マイグレーション。

$ heroku run rails db:migrate

これでPostgreSQLに接続できるはずです。。。

3
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?