1

On development, I set up a clever cloud MySQL database to my Django project with these settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'db-name',
        'HOST': 'db-name-mysql.services.clever-cloud.com',
        'PORT': 3306,
        'PASSWORD': 'password',
        'USER': 'user'
    }
}

It worked normally, so I created some data on this DB for testing.

I deployed this app on Heroku, and when I successfully deploy it, I realized that the data shown on Heroku, is not the same as my clever cloud DB. I don't know if Heroku is using another database or why is not using my database.

  • Heroku uses postgres natively, and your best bet is to migrate to that, but there are ways you can use MySQL with Heroku. Does this answer your question? [How to deploy local MySQL database to Heroku](https://stackoverflow.com/questions/15191259/how-to-deploy-local-mysql-database-to-heroku) – raphael Jan 23 '22 at 00:34
  • [Using remote MySQL database on Heroku running Django app](https://stackoverflow.com/questions/43544766/using-remote-mysql-database-on-heroku-running-django-app) I think this question explains better my problem, but there's still no answer. I have already deployed my database on clever cloud, so there is my connection on settings. @R.Uziel – Juan Carlos Hernández Jan 23 '22 at 00:43
  • Clever Cloud and Heroku are two different services. I don't think you can use the database from one in the other, nor do I understand why you would. Why not use Clever Cloud for both, keep your database and deploy your app to Clever Cloud? – raphael Jan 23 '22 at 01:16

1 Answers1

1

Original Answer

Clever Cloud and Heroku are two different services. I don't think you can use the database from one in the other, nor do I understand why you would. Why not use Clever Cloud for both, keep your database and deploy your app to Clever Cloud? To deploy to Clever Cloud, take a look at their docs.

Now if you want to deploy your app to Heroku, your best bet is to migrate to postgres since that is the native database for Heroku. But you can use MySQL on Heroku if you wish. For that you can use an addon that Heroku provides, ClearDB MySQL addon from Heroku.

EDIT

Though I still think my advice is correct, my answer may NOT be. You should be able to use an outside database in your Heroku app, as long as that outside app accepts connections from Heroku. And it is easy to do as Shan Valleru's answer describes. Basically you just have to run

heroku config:add DATABASE_URL=mysql://user:password@db-name-mysql.services.clever-cloud.com:3306/db-name
heroku config:add SHARED_DATABASE_URL=mysql://user:password@db-name-mysql.services.clever-cloud.com:3306/db-name

Then do

heroku restart

OR

You can change these variables in the Heroku panel as d1jhoni1b describes in his answer:

1 - create mysql db
2 - create mysql db user (set defaults)
3.1 - Go to your Heroku panel/Config Vars
3.2 - Click on "Reveal Vars" and edit (clicking on pencil icon) on the one you want to change in this case DATABASE_URL (if not present just a new one with DATABASE_URL as the name)

raphael
  • 2,469
  • 2
  • 7
  • 19
  • I thought that I can use a clever cloud database, because I deployed a java spring boot backend before in Heroku with a Clever Cloud DB. Thank you for your answer! :) – Juan Carlos Hernández Jan 24 '22 at 13:01
  • You're welcome! I'm surprised that you were able, but I don't know java spring boot. Perhaps there *is* a way, but It's probably best to use postgres, as the accepted answer at https://stackoverflow.com/questions/15191259/how-to-deploy-local-mysql-database-to-heroku says. Good luck! – raphael Jan 24 '22 at 13:35
  • 1
    I think you've already figured this out from the answer I see you posted [here](https://stackoverflow.com/questions/43544766/using-remote-mysql-database-on-heroku-running-django-app), but I wanted to let you know that I've edited my answer, @JuanCarlosHernández. – raphael Feb 13 '22 at 04:41