Report this

What is the reason for this report?

Weird issue with db schema generation when connected to a DO MySQL database

Posted on November 13, 2019

Hi, I’ve opened a ticket but I thought I’d ask here as well in case someone can help. I havre a Rails app that connects to a database in my MySQL cluster managed by DO. If I run migrations on that database, the schema.rb file generated isn’t valid and cannot be used for example for loading into an empty db. If, however, I do exactly the same thing but with a local (Docker) instance of MySQL 8.0.17 - exactly the same version as DO - then all is good. Is there any Rails developer here who could try dumping the schema while connected to DO MySQL?

Thanks!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.

First, make sure your database.yml file is configured correctly to connect to the DigitalOcean managed MySQL cluster. You should have something like this in your config/database.yml file:

  1. production:
  2. adapter: mysql2
  3. encoding: utf8
  4. url: <%= ENV['DB_URL'] %>
  5. username: <%= ENV['DB_USERNAME'] %>
  6. password: <%= ENV['DB_PASSWORD'] %>
  7. database: <%= ENV['DB_NAME'] %>
  8. pool: <%= ENV['DB_POOL'] %>

Ensure your environment variables are set correctly in the environment or in your app’s configuration (e.g., using a .env file with the dotenv gem).

After verifying your configuration, run the migrations using:

RAILS_ENV=production bundle exec rake db:migrate

Ensure your local version of MySQL is the same as the one you’re using on DigitalOcean. If the problem persists, please provide more information about the error message you’re receiving, and I’ll do my best to help you further.

For more information on connecting Ruby on Rails with DigitalOcean managed databases, refer to the official documentation.

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.