In this article, I will explain in an easy-to-understand manner how I got to solve the error that occurred when deploying on Heroku.
-The deployed application will be created with the TECH_CAMP curriculum.
・ Because the poster is a beginner, he / she may post incorrect information. At that time, I would appreciate it if you could point out without any refraining.
brew tap heroku/brew && brew install heroku
heroku login --interactive
~~ 3. Install rails_12factor Gem. ~~ ~~ → A Gem required to run a Rails application on Heroku. ~~
Rails_12factor gem is no longer needed in Rails 5 and later. </ b>
For details, see the Qiita article here.
heroku create application name
heroku addons:add cleardb
heroku_cleardb=`heroku config:get CLEARDB_DATABASE_URL`
Now you can assign the URL of the ClearDB database to a variable called heroku_cleardb.
heroku config:set DATABASE_URL=mysql2${heroku_creardb:5}
DATABASE_URL was reset by config: set.
heroku config:set RAILS_MASTER_KEY=`cat config/master.key`
git push heroku master
heroku run rails db:migrate
heroku apps:info
Was executed to move to the displayed URL.
When transitioning to the URL, the above error screen appeared.
Therefore, I returned to the terminal and checked the error log.
heroku logs --tail
The error log was displayed with the above command. The first thing I noticed was
2020-11-11T22:07:09.588453+00:00 (Omitted) dyno=web.1 connect=14ms service=35ms status=500 bytes=1827 protocol=https
Since status = 500, it can be seen that this is a server-side problem.
If you take a closer look,
Mysql2::Error::ConnectionError (Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)):
So, isn't MySQL not recognized on Heroku? I thought </ b>.
Looking back at the terminal code, I also found something strange about the MySQL settings.
nayuta@MacBookPro-Nayuta ajax_app % heroku_cleardb='heroku config:get CLEARDB_DATABASE_URL'
nayuta@MacBookPro-Nayuta ajax_app % heroku config:set DATABASE_URL=mysql2${heroku_creardb:5}
Setting DATABASE_URL and restarting ⬢ ajax-app-30306... done, v5
DATABASE_URL: mysql2
DATABASE_URL is not stored correctly.
My result
DATABASE_URL: mysql2
Correct result
DATABASE_URL: mysql2://000000000000:[email protected]/heroku_aaa00000000?reconnect=true
I thought there was no mistake here, but looking back at the work done in step 6, there was no misspelling of the command, and it seemed that it was entered correctly.
My input
heroku_cleardb='heroku config:get CLEARDB_DATABASE_URL'
Correct input
heroku_cleardb=`heroku config:get CLEARDB_DATABASE_URL`
I glared at the code, looked it up, and finally found out.
Where it should have been enclosed in `` (back quotation marks), it was enclosed in'' (single quotation marks).
It was a very simple mistake, but I was distracted by the spelling mistakes and was late to notice.
nayuta@MacBookPro-Nayuta ajax_app % heroku_cleardb=`heroku config:get CLEARDB_DATABASE_URL`
nayuta@MacBookPro-Nayuta ajax_app % heroku config:set DATABASE_URL=mysql2${heroku_cleardb:5}
Setting DATABASE_URL and restarting ⬢ ajax-app-30306... done, v12
DATABASE_URL: mysql2://bf691ece578431:[email protected]/heroku_b4193d2f6e19e50?reconnect=true
If you enclose it properly in ``, the URL reset is completed.
However, even if you push it as it is, the following error message will appear, so
Everything up-to-date
I made an empty commit and had it pushed together.
git commit --allow-empty -m "Empty commit"
git push heroku master
It seems that it was pushed normally, so when I transitioned to the URL, the created application was deployed.
I was careful about spelling mistakes because I often get errors due to typos, but I never imagined that I would make typos in'' and ``. It was a very terrible mistake, but I was fortunate because I gained more experience points saying "I made an error because of such a mistake!".
Recommended Posts