I can’t figure out why Django doesn’t use the database engine I specify in the settings.py file but instead uses value django.db.backends.dummy.
Here is the DB part of my settings.py file which is located at /project/app/settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db_name',
'USER': 'my_user',
'PASSWORD': 'my_pass',
'HOST': '',
'PORT': '',
}
}
And here is what Django debug log shows:
DATABASES
{'default': {'ENGINE': 'django.db.backends.dummy',
'HOST': '',
'NAME': 'my_db_name',
'OPTIONS': {},
'PASSWORD': u'********************',
'PORT': '',
'TEST_CHARSET': None,
'TEST_COLLATION': None,
'TEST_MIRROR': None,
'TEST_NAME': None,
'TIME_ZONE': 'UTC',
'USER': 'my_user'}}
I’m running this site in production with gunicorn and nginx. The site has currently setup debug mode to True.
UPDATE 1: When I run python manage.py diffsettings I get the following (the engine is correct):
DATABASES = {'default': {'ENGINE': 'django.db.backends.mysql', 'TEST_MIRROR': None, 'NAME': 'my_db_name', 'TEST_CHARSET': None, 'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'OPTIONS': {}, 'HOST': '', 'USER': 'my_user', 'TEST_NAME': None, 'PASSWORD': 'my_pass', 'PORT': ''}}
UPDATE 2: I tried also this in shell, works as expected, I can reach my db:
# python manage.py shell
>>> from myapp.models import MyModel
>>> test = MyModel.objects.all()
>>> test
# Outputs all objects from MyModel.
UPDATE 3: Something strange is happening. To debug this problem I commented out all INSTALLED APPS in the settings.py, restarted nginx, but Django still shows them in the debug log:
INSTALLED_APPS
('django.contrib.auth',
'django.contrib.humanize',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grappelli',
'django.contrib.admin',
'foureggs',
'registration',
'massadmin')
It looks like Django is using some kind of cached version of my settings.py file.
Here is what fixed my problem in the end. I’m not sure what was the real cause but it looks like it had something to do with running supervisord.
I had 2 virtual environments defined under my domain (i.e. /home/mydomain/www/env1 and /home/mydomain/www/env2). The problem I described in the original question was with the env2.
I first thought that it’s the env1 that’s causing the problems and somehow its settings.py is used instead of settings.py from env2. But settings.py in env1 looked totally different so that probably wasn’t the issue.
Anyway, here are the steps I’ve taken, it might give some pointers to others running into the same issue:
I deleted env1 (/home/mydomain/www/env1) <– this is probably not related to the problem but I deleted the envivornment anyway since I didn’t need it
I killed these processes: supervisord, nginx, gunicorn_django (i.e.
pkill supervisord)I started supervisord (which runs the bash script to start gunicorn_django process) and nginx
Site now worked as expected.