title: The connection "database" doesn't exist Django, CentOS7, NGINX, UWSGI
body: <p>I'm running a CentOS 7.2 server with UWSGI serving my django app. However, after much troubling and config problems I managed to get it to start up. However, it shows the login page, and then 500 errors out. The 500 error is because it can't connect to a table "auth_user". I have a database and I've connected to it using the databases parameter in settings.py, however it is empty. When I run python <code>manage.py migrate --database="mydatabasename"</code> it gives me an error that says "django.db.utils.ConnectionDoesNotExist: The connection "databasename" doesn't exist" I've spent the last week looking at it and I can't seem to discover what is happening. </p>
  
  <p>The database exists and if I run "python manage.py shell", then I import MySQLdb, and connect to the database with the exact same parameters (still localhost), it works perfectly fine and it can connect with no issue.</p>
  
  <p>Does any experts know what is happening and why there is not a database connection? I have installed mariadb and then of course the secured setup for mysql. I've created the database and assigned a user/password to it. I can login with the username and password as well via mysql and it works on localhost from my virtual environment.</p>
  
  <p>This is my structure...</p>
  
  <pre><code>myapi
    -api
      --admin.py
      --serializers.py
      --urls.py
      --etc
    -myapp
      --settings.py
      --urls.py
      --wsgi.py
    -myvirtualenvironment
    manage.py
    requirements.py
  </code></pre>
  
  <p>Here are my relevant files...</p>
  
  <p>Settings.py</p>
  
  <pre><code>import os
  BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  SECRET_KEY = 'my secret key'
  SESSION_COOKIE_SECURE = True
  CSRF_COOKIE_SECURE = True
  DEBUG = True
  ALLOWED_HOSTS = ['*']
  
  
  STATIC_ROOT = os.path.join(BASE_DIR, "static/")
  INSTALLED_APPS = (
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'api',
      'rest_framework',
  )
  MIDDLEWARE_CLASSES = (
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
       'django.middleware.security.SecurityMiddleware',
       'django.middleware.clickjacking.XFrameOptionsMiddleware',
       'django.middleware.csrf.CsrfViewMiddleware',
  )
  REST_FRAMEWORK = {
      'DEFAULT_AUTHENTICATION_CLASSES': (
          'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
      )
  }
  ROOT_URLCONF = 'myapp.urls'
  WSGI_APPLICATION = 'myapp.wsgi.application'
  
  ADMINS = [('my name', 'my email')]
  EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  EMAIL_HOST = 'myhost'
  EMAIL_HOST_USER = 'myuser'
  EMAIL_HOST_PASSWORD = 'mypassword'
  EMAIL_PORT = myport
  EMAIL_USE_TLS = False
  SERVER_EMAIL = "server email"
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.sqlite3',
          'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
      }
  }
  LANGUAGE_CODE = 'en-us'
  TIME_ZONE = 'UTC'
  USE_I18N = True
  USE_L10N = True
  USE_TZ = True
  LOGIN_URL = '/admin/login/'
  STATIC_URL = '/static/'
  STATIC_ROOT = BASE_DIR + '/static/'
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [os.path.join(BASE_DIR, 'templates')],
          'APP_DIRS': True,
          'OPTIONS': {
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.contrib.messages.context_processors.messages',
              ],
              'debug': DEBUG
          },
      },
  ]
  
  AUTH_PASSWORD_VALIDATORS = [
      {
          'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
      },
  ]
  
  if 'DJANGO_PRODUCTION' in os.environ:
      STATIC_URL = '/api/v1' + STATIC_URL
      LOGIN_URL = '/api/v1' + LOGIN_URL
      MEDIA_ROOT = '/var/www/myapi/api_files/'
      MEDIA_URL = '/api_files/'
      CORS_ORIGIN_ALLOW_ALL = False
      DEBUG = False
  
      DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.mysql',
              'NAME': 'mydatabasename',
              'USER': 'myuser',
              'PASSWORD': 'mypass',
              'HOST': '127.0.0.1',
              'OPTIONS': {
                  'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
              },   
              'PORT': 'myport',
          }
      }
  
  # CELERY SETTINGS
  #REDIS_HOST = 'localhost'
  #REDIS_PORT = myport
  #REDIS_DB = 0
  
  #BROKER_URL = 'redis://%s:%d/%d' % (REDIS_HOST, REDIS_PORT, REDIS_DB)
  #CELERY_RESULT_BACKEND = 'redis://%s:%d/%d' % (REDIS_HOST, REDIS_PORT, REDIS_DB)
  
  X_FRAME_OPTIONS = 'DENY'
  CSRF_COOKIE_HTTPONLY = True
  SECURE_SSL_REDIRECT = True
  SECURE_CONTENT_TYPE_NOSNIFF = True
  SECURE_BROWSER_XSS_FILTER = True
  </code></pre>
  
  <p>And then here is my nginx conf file...</p>
  
  <pre><code>location /api/v1/ {
      root /var/www/myroot;
      include uwsgi_params;
      uwsgi_param SCRIPT_NAME /api/v1;
      uwsgi_modifier1 30;
      proxy_set_header SCRIPT_NAME /api/v1;
      uwsgi_pass unix:/run/uwsgi/myapp.sock;
      location /api/v1/static {
          alias /var/www/myapp/static;
      }
  }
  </code></pre>
  
  <p>And here is my wsgi conf file....</p>
  
  <pre><code>import os
  import sys
  os.environ['HTTPS'] = "on"
  os.environ.setdefault("DJANGO_PRODUCTION", "1")
  
  tempvar= "/var/www/myapp/api"
  if not tempvar in sys.path:
      sys.path.insert(0, tempvar)
  api = "/var/www/bidjobapi"
  if not api in sys.path:
      sys.path.insert(0,api)
  
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
  
  from django.core.wsgi import get_wsgi_application
  application = get_wsgi_application()
  </code></pre>
  
  <p>And here is my uwsgi file....</p>
  
  <pre><code>project = myproject
  username = myuser
  base = /var/www/myapi
  chdir = %(base)/%(project)
  home = %(base)/myvenv/
  module = wsgi:application
  master = true
  processes = 5
  uid = %(username)
  socket = /run/uwsgi/myapp.sock
  chown-socket = %(username):nginx
  chmod-socket = 664
  vacuum = true
  uid = %(username)
  gid = %(username)
  logto = /var/log/uwsgi/%(project).log
  </code></pre>
  
  <p>my manage.py has the following.</p>
  
  <pre><code>os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
  </code></pre>
  
  <p>Does anyone see what the problem is and what is going on?</p>