LoginSignup
1
2

More than 3 years have passed since last update.

デプロイできない!heroku に push できないエラーを解決する (Rails チュートリアル1章)

Last updated at Posted at 2020-07-17

自分がrailsチュートリアルを進めていく上で、発生したエラーを記録していきます。
ハードはMacBook Air, 開発環境はVScodeを用いています。

Railsチュートリアル1章 1.5 デプロイする

「よしデプロイするぞ!GitHubにプッシュするやり方と似てるゾ!」
「これならできる!!!!!!」

$ heroku login
$ git init
$ heroku git:remote -a アプリの名前
$ git add .
$ git commit -am "first commit"
$ git push heroku master

:small_red_triangle_down:その結果

$ git push heroku master
~省略~
remote:        Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
~省略~
remote:        Could not create Makefile due to some reason, probably lack of necessary
~省略~
remote:        An error occurred while installing sqlite3 (1.4.2), and Bundler cannot continue.
~省略~
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !     Detected sqlite3 gem which is not supported on Heroku:
remote:  !     https://devcenter.heroku.com/articles/sqlite3
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to tutorial-app-20200717.
remote: 
To https://git.heroku.com/アプリ名.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/アプリ名.git'

と、頭を抱えることになります。

gitにプッシュした後、herokuにデプロイするぞ!とそのまま突き進んだ人がハマるエラーです。

このエラーは、HerokuではSQLiteがサポートされていないために発生します。
そこでデータベースをPostgreSQLに変更します。

「よし!解決方法がわかったからやっていくぞ!」と、1.5.1 Herokuのセットアップや、初心者です。Herokuでbuildに失敗し続けてしまいます。。を試してみるものの、上手くいきません...

上記のサイトの方法を試しても駄目だった人は、一から作り直すことになりますが、最終手段として次の方法を試してみてください。

解決方法

rails new の段階でデータベースをPostgreSQLに指定する!

また一からやり直す解決策になりますので、ご了承ください...
「大丈夫みんなならできるよ!」

早速やっていきましょう。

変更前
$ rails _5.1.6_ new アプリ名
変更後
$ rails _5.1.6_ new アプリ名 --database=postgresql

これを実行すると、最初からPostgreSQLが指定されたrailsフレームワークが生成されます。

あとは、これまでと同様の手順で進めて大丈夫です。一通り設定が終わりましたら、herokuにpushしてみてください。

ここまでやればherokuに問題なくデプロイできるようになります。

役に立ったら是非LGTMボタンをポチッと押していただけると嬉しいです。
一緒に Rails学習 頑張りましょう!:raised_hand_tone1:


ちなみに、railsのバージョン指定をせずに、rails6でこの操作を実行すると、次のようなエラーが発生します。

$ rails s

を実行し、localhost:3000にアクセスしてみてください。

赤いエラー画面に、次のようなエラー文が表示されるはずです。
FATAL: database "アプリ名" does not exist
ActiveRecord::NoDatabaseError

この場合の解決方法はこちらにまとめました。
rails6で ActiveRecord::NoDatabaseError を解決する

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