ruby '2.6.5' gem 'rails', '~> 6.0.0' gem 'mysql2', '0.5.3'
This time I created an application from scratch, and since I had a framework to some extent, I pushed it to heroku. The top screen was displayed safely, but when I go to the new registration screen or login screen, an error occurs, so I will write the method to read the error statement and resolve it.
First of all, from the result, it was because the database and the application were not connected well.
%heroku create application name
Now create a database. Create and confirm with the code below.
% git config --list | grep heroku
If anything other than fatal: not in a git directory is displayed, it's OK.
In Heroku, the database settings used are PostgreSQL by default. This time, we will configure the settings to use the same MySQL as the development environment.
A tool for using MySQL. An add-on provided by a database service called ClearDB that allows you to use MySQL on Heroku.
% heroku addons:add cleardb
You have now set your database to MySQL.
Next, since the version of MySQL needs to match the version of the corresponding Gem, execute the following command.
％ heroku config | grep CLEARDB_DATABASE_URL
CLEARDB_DATABASE_URL is created. In this application Since we are using a gem called mysql2, we need to change the mysql: // part to something like mysql2: //.
heroku config:set DATABASE_URL='mysql2://000000000000:email@example.com/heroku_aaa00000000?reconnect=true'
、mysql:// → mysql2://
The above part is different for each application.
I wasn't able to do mysql: // → mysql2: // here. So it was said that the database could not be connected well.
Do I have to delete the database to reset it? I searched for things like deleting CLEARDB_DATABASE_URL, but it wasn't.
CLEARDB_DATABASE_URL can be reset.
% heroku config:set DATABASE_URL='mysql2://[Application CLEARDB_DATABASE_URL]=true'
I solved it here.
And after this
% git push heroku master
Push to heroku,
% heroku run rails db:migrate
to hold. It's a pattern that beginners tend to forget, so don't forget to migrate.
I accessed the application and checked the new posting screen, but I was able to access it safely.