Forums

Accessing wrong database

Hi, I got 2 python apps with the same git code base and 1 of them keeps giving a 500 Server error if you try and do anything that accesses the database. My settings.py file contains this database.

DATABASES = {
241         'default': {
242             'ENGINE': 'django.db.backends.mysql',
243             'NAME': 'conceptpyrota$customerservice_20220628',
244             'USER': 'conceptpyrota',
245             'PASSWORD': xxxxxxx',
246             'HOST': 'conceptpyrota.mysql.pythonanywhere-services.com',
247             'OPTIONS': {
248                 "init_command": "SET sql_mode='STRICT_TRANS_TABLES'",
249             }
250         }
251     }

I can verify this 100% as I do a print and when i do a python manage.py command, it displays the database as above. However, in the server error log, it seems to be trying to access a different, older database, which has been deleted.

django.db.utils.OperationalError: (1049, "Unknown database 'conceptpyrota$callcenter_20220616'")

This is the previous database I was using, now deleted. What is going on here? Is there some kind of caching issue? I tried deleting the settings.pyc file and it didn''t do anything. So at the moment I have an app that fails to work, except show me the landing page.

Any suggestions?

Edit: Just to add to my own post, it seems the html being served is not the same as in the folder. I even looked with vi and it's different. So it seems the web app is using some type of cache or something is really wrong. But I can't tell.

Did you reload your web app after making changes to the settings?

Yes, a number of times.

Then you have some other code that is actually what your web app is running for the settings that is different to the code that you've been editing. Check which settings your web app is actually using.

I found the issue!. I moved the app to a different folder weeks ago and moved everything accordingly. What I failed to change was the correct folder in the WGSI file. I only found this when I deleted the entire web app and set it up again from scratch. I'm surprised the app was even running at all from a folder (at least one I can't see) for weeks. No wonder I was banging my head on the wall. An error such as "file not found" would have made this so much easier to diagnose for me, instead of running from a code base/database that no longer exist. Just posting this to help anyone else that might make the same error.

If the file that your wsgi was pointing to was not there, then your web app would not have worked after being reloaded. The reload process needs to import the settings from the file you specify and, if it is not there, the reload will fail and the web app will not start up.