After deploying to heroku and opening it, you will see this screen ↓
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.
[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!
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
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.
[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, ...
I opened it!
You did it! !! !!
Recommended Posts