[RUBY] I can deploy to heroku, but I get an error and can't open it [Cause: MySQL]

error

After deploying to heroku and opening it, you will see this screen ↓

スクリーンショット 2020-06-16 15.51.04.png

solution

Heroku doesn't default to MySQL, so you have to set it yourself.

These two articles are easy to understand! ↓

--Set with CUI https://qiita.com/senou/items/108ef1d94dcb5b227b4f

--Set by GUI https://qiita.com/poster-keisuke/items/f27e190e22d80dc254ed

After reading these two articles and getting an overview, I set it up with CUI.

Change heroku database to MySQL

[vagrant@localhost memopy]$ heroku addons:create cleardb:ignite
Creating cleardb:ignite on ⬢ memopy... free
Created cleardb-aerodynamic-24825 as CLEARDB_DATABASE_URL
Use heroku addons:docs cleardb to view documentation

[vagrant@localhost memopy]$ heroku config | grep CLEARDB_DATABASE_URL
CLEARDB_DATABASE_URL:     mysql://bc0ee5063e4f00:[email protected]/heroku_fb9e9b74813be35?reconnect=true

[vagrant@localhost memopy]$ heroku config:set DATABASE_URL=mysql2://bc0ee5063e4f00:[email protected]/heroku_fb9e9b74813be35?reconnect=true
Setting DATABASE_URL and restarting ⬢ memopy... done, v7
DATABASE_URL: mysql2://bc0ee5063e4f00:[email protected]/heroku_fb9e9b74813be35?reconnect=true

[vagrant@localhost memopy]$ heroku config
=== memopy Config Vars
CLEARDB_DATABASE_URL:     mysql://bc0ee5063e4f00:[email protected]/heroku_fb9e9b74813be35?reconnect=true
DATABASE_URL:             mysql2://bc0ee5063e4f00:[email protected]/heroku_fb9e9b74813be35?reconnect=true
LANG:                     en_US.UTF-8
RACK_ENV:                 production
RAILS_ENV:                production
RAILS_LOG_TO_STDOUT:      enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE:          57c40cfca095d1fb6419a4e567f5d16f11d3d5827d045def500cff321f31bfa7aefe3ebc740f678ea62a4db48a32f76c7d7569c06295d7aed89d8df62a87b7c4

Now you can use MySQL on heroku!

Supplement

zsh: no matches found: DATABASE_URL=mysql2://bf308b6fe98a5e:[email protected]/heroku_a8b1a434e18a217?reconnect=true

If this error appears, it is a zsh error, so add the following to .zshrc ↓

$ setopt nonomatch

Then reflect the changes.

$ source ~/.zshrc

For details, refer to this article ↓ https://khanamoto.hatenablog.com/entry/2018/05/09/183947

Asset pipeline settings

It seems that we also have to set up an asset pipeline. If you're looking for an asset pipeline, read this article. ↓ https://www.transnet.ne.jp/2016/02/28/rails%E5%88%9D%E5%AD%A6%E8%80%85%E3%81%8C%E3%81%A4%E3%81%BE%E3%81%9A%E3%81%8Dcolnr%E3%80%8C%E3%82%A2%E3%82%BB%E3%83%83%E3%83%88%E3%83%91%E3%82%A4%E3%83%97%E3%83%A9%E3%82%A4%E3%83%B3/

Looking at config / environments / production.rb,

(Omitted)
config.assets.compile = false
(Omitted)

Because it was

(Omitted)
config.assets.compile = true
(Omitted)

change to.

migration

[vagrant@localhost memopy]$ git add -A

[vagrant@localhost memopy]$ git commit -m 'Asset pipeline settings'

[vagrant@localhost memopy]$ git push

[vagrant@localhost memopy]$ git push heroku master

[vagrant@localhost memopy]$ heroku run rake db:migrate

This completes migrate!

If you open it with heroku open, ...

スクリーンショット 2020-06-16 15.54.46.png

I opened it!

You did it! !! !!

Recommended Posts

I can deploy to heroku, but I get an error and can't open it [Cause: MySQL]
I can deploy Heroku, but I get an error and can't open it
I built a CentOS 8 environment with Vagrant and tried to sync_folder, but I got an error, so I solved it.
When you deploy to Heroku but it doesn't reflect well
[Rails] I can post S3 images in my local environment, but I can't switch to S3 on Heroku.
I got an error and couldn't push! !! [error: failed to push some refs to]
I was able to deploy the Docker + laravel + MySQL app to Heroku!
I get an error with bundle install and puma cannot be installed.
What to do if you get an error when you hit Heroku logs
When registering a new user, I got an error called ActiveRecord :: NotNullViolation and how to deal with it.
Deploy to heroku with Docker (Rails 6, MySQL)
I created a Rails post form, but I can't post it (form tag) / No error occurs
What to do if you get an error on heroku rake db: migrate
Where can I get OpenJDK binaries and archives?
I get an error when adding a dependency
When deploying to Heroku, OpenApp causes an error
[Mockito] 3.2.4 → 3.3.x, but I got an error (Iketenai)
Deploy to Heroku (for second and subsequent edits)
Error deploying rails5 + Mysql to heroku with Docker-compose
[Rails] How to get success and error messages
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (5)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (6)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (2)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (1)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (4)