Search code examples
mysqlherokudeploymentremote-accesspythonanywhere

Connecting to MySQL database located at (pythonanywhere.com) from app located at (heroku.com)


I created a webb app and deployed it at Heroku. So far, so good. Now I need to integrate it with the MySQL database which is located at pythonanywhere.com.

I tried the following command (which is what I managed to find when googling for accessing a remote MySQL database from Heroku):

heroku config:add DATABASE_URL=mysql2://PYTHONANYWHERE_USER:DATABASE-HOST-ADDRESS/DATABASE-NAME--app HEROKU-APP-NAME

Whenever I run this command from the console in Heroku, I get the following message:

bash: heroku: command not found

Have anyone tried connecting to a pythonanywhere MySQL database from Heroku before? Can you show how you did this step-by-step?

The reason why I want to access the PythonAnywhere database (and not just host it on Heroku) is that a lot of the backend is written on PythonAnywhere and stored on that database.

Thanks,


Solution

  • The heroku command is provided by the Heroku CLI, and should be installed and run from your local machine. Running heroku commands directly from a dyno (e.g., via heroku run bash) won't work.

    Once you've set DATABASE_URL using heroku config you should be able to access it from your code via process.env.DATABASE_URL.