LoginSignup
50
40

More than 3 years have passed since last update.

Herokuでデプロイした際にApplication error(エラーコードH10 (App crashed))が出た時の対処法

Posted at

環境

Ruby 2.6.3
Rails 5.2.3

現象

Railsアプリケーションを作成後、Herokuへデプロイした際に以下画像のエラーが発生。
その際の対処法を備忘録として残しておきます。

https___qiita-image-store.s3.amazonaws.com_0_110452_526e9c21-ec79-5305-c7e5-b536f689a3c4.jpeg

 【対処方法】エラーの原因を把握する

以下コードで状況を把握します。

$ heroku logs --tail

エラーコードが確認できました。

2019-11-26T05:06:44.357974+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=agile-meadow-66722.herokuapp.com request_id=e2c36b19-f3d1-4544-9f84-5ddcb7027cd2 fwd="219.113.146.130" dyno= connect= service= status=503 bytes= protocol=https
2019-11-26T05:06:44.823379+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=agile-meadow-66722.herokuapp.com request_id=c5d323a0-b4be-497c-847b-2d3ebf4942d0 fwd="219.113.146.130" dyno= connect= service= status=503 bytes= protocol=https

エラーコードの中身を読んでみると、code=H10でApp crashedとのこと。
ネットで調べてみたところ、以下のようにリスタートすれば直ることもあると情報があったため試しました。

$ heroku restart -app

もしくは

$ heroku restart -app application_name

しかし、こちらを試してもエラーのままでした。

コンソールを開いて詳細エラー情報を確認する。

エラーの詳細内容を確かめるために以下コードでHeroku上でコンソールを開きました。

$ heroku run rails c

すると、以下エラーコードが出てきました。

Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile. (LoadError)

sqlite3がバンドルされていない?Gemfileに加えろとの指示。
しかし、sqlite3は本番環境に対応していません。

どうやらrails newの時点でpostgresqlの指定を忘れていてsqlite3がデータベース作成時に指定されていたみたいです・・・

アプリ作成初期段階の凡ミスでエラーが発生することになりました。

SQLite3からPostgreSQLに変換

※参照
https://qiita.com/isotai/items/67bafc37a16ea5de5e3b

上記記事を参考にし、
datebase.ymlのsqlite3時点の記載内容を全て消し、
postgresql指定でrails newした場合の記載に変更しました。

gemfileに以下を追加しました。

gem 'pg', '>= 0.18', '< 2.0'

以上。

50
40
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
50
40