[RUBY] What to do if you get an error on heroku rake db: migrate

I'm a beginner in programming and studying, but I couldn't get any information even if I googled, so I'll report it.

environment

Mac OS X Ruby: 2.7.1 Rails: 6.0.3.4 heroku stack: heroku-20 (when an error occurs) DB: MYSQL

What happened

https://qiita.com/murakami-mm/items/9587e21fc0ed57c803d0 When I tried to deploy to heroku referring to this article,

console


$ heroku rake db:migrate

When you run

console


Mysql2::Error::ConnectionError: SSL connection error: error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol

I got an error.

Cause / Countermeasure

Cause

There are two reasons why this error occurred in my environment

➀ heroku stack was heroku-20 ➁ There was no necessary description in config/database.yml

Coping

➀ heroku stack was heroku-20 → Make heroku-18 available

console


heroku stack:set heroku-18 -a <app name>

➁ There was no necessary description in config/database.yml Add the following code to production

config/database.yml


production:
  url: <%= ENV['DATABASE_URL'] %>

Reason

We are always looking for good reasons. .. Please let me know. ..

➀ heroku stack was heroku-20 Didn't you write the necessary processing that came out by changing to heroku-20? → Solved for the time being by using heroku-18 so far

➁ There was no necessary description in config/database.yml

There seems to be such a description in config/database.yml (I disappeared for some reason)

config/database.yml



# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
#   DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
#   production:
#     url: <%= ENV['DATABASE_URL'] %>

Especially this time, the description in the latter half is important

config/database.yml


# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
#   DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
#   production:
#     url: <%= ENV['DATABASE_URL'] %>

Roughly translated into Japanese

"On Heroku and other platforms, you'll get various URLs in the form of environment variables. DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" You can use this data structure like this production: url: <%= ENV['DATABASE_URL'] %>」

The point is that I didn't have this description, so I didn't know which database to use and got an error.

Summary

If something goes wrong and you don't understand even if you google, check the version of what you are using!

Thank you for reading.

Recommended Posts

What to do if you get an error on heroku rake db: migrate
What to do if you get an error during rails db: reset
What to do if you get an error when you hit Heroku logs
What to do if you get an uninitialized constant Likes Controller error
# What to do if you accidentally do rails db: migrate: drop
What to do if you get the error Couldn't find Item without an ID
What to do if you get a port error when docker-compose up on Mac
What to do if you get a gcc error in Docker
What to do if you get a DISPLAY error in gym.render ()
[Rails] What to do if you can't get an error message with the errors method
What to do if you get an error in Basic authentication during Rails test code
no space left on device What to do if an error occurs
What to do if you get a MiniMagick vulnerability alert on GitHub
What to do if you get an [An HTTP request took too long to complete.] Error in Docker.
What to do if you get the error message unrecognized selector send to instance "***"
What to do if you get the error Too long with no output (exceeded 10m0s) on CircleCI
What to do if you get a java.io.IOException in GlassFish
What to do if you get a wrong number of arguments error in binding.pry
What to do if you can't get the text of an element in Selenium
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do if you get an "A server is already running." Error when you try to start the rails server
[Java] What to do if you get an error in Eclipse saying "Not allowed at source level below 1.X"
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
What to do if you get angry with OpenSSL with pyenv install
What to do if you get a "302" error in your controller unit test code in Rails
What to do if you install Ubuntu
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
[Rails] What to do if you can't get parameters with form_with
What to do if you go offline due to SSL certificate error when running Jenkins on Mac
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if you get a groovy warning in Thymeleaf Layout
What to do if an error occurs when nokogiri enters when bundle install
What to do if deployment fails on Heroku (Ruby app not detected)
What to do if you push incorrect information
What to do if you should have installed Rails but an error occurs with rails -v (for beginners)
What to do if you get Could not locate Gemfile or .bundle / directory
What to do if you have installed Java for OS X on macOS
wildflly10 java8 ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906 What to do if an error occurs
What to do if you get angry if you don't have nokogiri while installing wp2txt
What to do if you get To install the missing version, run `gem install bundler: 2.1.4`
What to do if TextToSpeech doesn't work on Android 11
What to do if you accidentally create a model
What to do if you can't find your API key after deploying to Rails heroku
What to do when you launch an application with rails
What to do if audio is not available on discordrb
What to do if mysql2 gets a bundle install error
What to do if you can't use the rails command
What to do if you switch Java versions on Windows 7 and get Error: Registry key'Software \ JavaSoft \ Java Runtime Environment'\ CurrentVersion' has value '1.8', but '1.7' is required.
What to do if you don't see the test code error message in the terminal console
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
What to do when an error occurs in rails db: migrate ((StandardError: An error has occurred, this and all later migrations canceled :))
What to do when an error (StandardError: An error has occurred, this and all later migrations canceled:) appears in rails db: migrate
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
DB error on deploying with Heroku
[Rails] What to do if data is not registered in DB
What to do if you forget the root password in CentOS7
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate