[Ruby] I can’t deploy! Resolve errors that cannot be pushed to heroku (Rails Tutorial Chapter 1)

2 minute read

As you progress through the rails tutorial, record the errors that occurred. Hardware uses MacBook Air, and development environment uses VScode.

Rails Tutorial Chapter 1 1.5 Deploy

“Okay, let’s deploy! It’s similar to pushing to GitHub!” “This can be done!!!”

$ heroku login
$ git init
$ heroku git:remote -a App name
$ git add.
$ git commit -am "first commit"
$ git push heroku master

:small_red_triangle_down:the result

$ 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:! Failed to install gems via Bundler.
remote: !Detected sqlite3 gem which is not supported on Heroku:
remote: !https://devcenter.heroku.com/articles/sqlite3
remote: !Push rejected, failed to compile Ruby app.
remote: !Push failed
remote: Verifying deploy...
remote: !Push rejected to tutorial-app-20200717.
To https://git.heroku.com/appname.git
 ![remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to'https://git.heroku.com/appname.git'

And you will be holding your head.

After pushing to git, deploy to heroku! That’s an error that people who push forward as it is.

This error occurs because **Heroku doesn’t support SQLite. So change the database to PostgreSQL. **

“Okay! I know how to solve it, so I’ll do it!” 1.5.1 Heroku setupandI’mabeginner…MybuildkeepsfailingonHeroku… I try, but it doesn’t work…

**If you’ve tried the methods on the site above and aren’t happy, you’ll have to recreate them from scratch, but try the following as a last resort: **


Specify the database for PostgreSQL at the rails new stage!

Please understand that it will be a solution to start over again… “Everyone can do it!”

Let’s do it right away.

Before change

$ rails _5.1.6_ new App name

After change

$ rails _5.1.6_ new App name --database=postgresql

Running this will generate a rails framework with PostgreSQL specified from the beginning.

After that, you can proceed with the same procedure as before. Please push to heroku when setting is completed.

By doing so, you will be able to deploy to heroku without problems.

If you find it useful, please feel free to press the LGTM button. ** Learn Rails together Let’s do our best! :raised_hand_tone1:

By the way, if you do this operation on rails6 without specifying the rails version, the following error will occur.

$ rails s

Please try to access localhost:3000.

On the red error screen, you should see the following error statement: FATAL: database “app name” does not exist ActiveRecord::NoDatabaseError

The solution in this case is summarized here. Resolve ActiveRecord::NoDatabaseError with rails6