DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on

A trap point at "push your rails app to Heroku which uses mysql"

A trap point at "Push to Heroku your rails app with mysql"

🤔Situation

  • I have a Heroku account
  • I have installed Heroku CLI, and Logged in.
  • I set my env into Heroku
  • I add the "ClearDB MySQL" Add-Ons.
  • I made sure the connection from my laptop to the ClearDB by sequel-pro
  • My rails app run on my local with mysql2
$ brew tap heroku/brew && brew install heroku
$ heroku login
$ heroku config -a my-app-name
=== my-app-name Config Vars
CLEARDB_DATABASE_URL:     mysql://user_name:password@host/database_name?reconnect=true
DATABASE_URL:             mysql://user_name:password@host/database_name?reconnect=true
DB_HOST:                  host
DB_NAME:                  database_name
DB_PASSWORD:              password
DB_USERNAME:              user_name
LANG:                     en_US.UTF-8
RACK_ENV:                 production
RAILS_ENV:                production
RAILS_LOG_TO_STDOUT:      enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE:          xxxxxxxxxxxxxxx

🚧 Trap point

I faced like the error.

LoadError: Could not load the 'mysql' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile.

🦄 Solution

I've changed the enviroment variables

form mysql://user_name:password@host/database_name?reconnect=true
to mysql2://user_name:password@host/database_name?reconnect=true

👍 then,..

It makes Heroku deploy your app again. Maybe you need to run migrate again.

$ heroku run -a my-app-name bundle exec rails db:migrate

👍 for debag

$ heroku run -a my-app-name bundle exec rails console

Top comments (1)

Collapse
 
aojedal profile image
Arturo Ojeda

Concise and to the point, thanks!