0

I've been struggling with the following problem: I have a MySQL database running on a remote web host. I connect to the MySQL database in my Django app (I use it as the main database). The Django app is running on a Heroku server but I get different data results compared to running it locally.

Am I missing something, or are changes done on Heroku not committed to the database?

MySQL settings:

DATABASES = {
 #   'default': {
  #      'ENGINE': 'django.db.backends.sqlite3',
   #     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
   # }
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'xxx',
        'USER': 'xxx',
        'PASSWORD': 'xxx',
        'HOST': 'xxx',
        'PORT': 'xxx',
    }
}
6
  • Please show your settings. Are you sure the app on Heroku is connecting to the remote MySQL db? Commented Apr 21, 2017 at 14:19
  • Updated the question with the MySQL settings. Yes I am sure, though the MySQL database is configured in the Django app, not in Heroku (if possible/necessary). Commented Apr 21, 2017 at 14:25
  • And there's nothing else in that settings file that could be overriding that DATABASES setting? Commented Apr 21, 2017 at 14:26
  • No, it is the only DATABASES setting in the file. Is it required to host your database on Heroku or should this work (if set up correctly)? Commented Apr 21, 2017 at 14:29
  • 1
    Assuming your MySQL db is set up to accept connections from the internet, this should work. But if it didn't, your site wouldn't work at all; you wouldn't just get different data. Which is why the only explanation I can think of is that you are somehow overriding your settings somehow. Sorry to keep insisting, but for example are you sure there's no call to dj_database_url? Commented Apr 21, 2017 at 14:31

2 Answers 2

1

I just see that if you delete the ad-on provided by heroku, it will use the DB you put on the settings of your project

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
1

I believe Juan Carlos Hernández is correct. To expand on his answer, Heroku uses it's own database instance, unless you tell it otherwise by pointing the DATABASE_URL to the one you would like to use. Please note that Heroku will prevent you from overwriting the DATABASE_URL in use since that will destroy the existing database. Although tagged as ruby-on-rails, the answers I found here seem relevant.

To summarize, you just have to run

heroku config:add DATABASE_URL=mysql://dbusername:dbpassword@databasehostIP:3306/databasename
heroku config:add SHARED_DATABASE_URL=mysql://dbusername:dbpassword@databasehostIP:3306/databasename

Then do

heroku restart

Or you can change these variables in the Heroku panel.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.