Search code examples
pythondjangodjango-manage.py

Fed up with the error ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value


ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value

I am suffering from this problem since last 3 days.

I have seen tones of duplicates tickets on different blogs (even on stackoverflow) and solutions as well but none of them worked form me.

Finally I have no option but to ask what is wrong here in my settings.py and why is the problem not going even after shifting django app on new AWS instance.

my setting.py:

# Django settings for smartDNA project.
import os
import sys
import logging
from django.conf import settings

DEBUG = True
TEMPLATE_DEBUG = DEBUG
WINDOWS=False
#EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_USE_SSL = True
#EMAIL_USE_TLS = True
EMAIL_HOST = 'xxx.xxx.xxx.xxx'
EMAIL_PORT = 80 
EMAIL_HOST_USER = 'xxxx@xxxx'
EMAIL_HOST_PASSWORD = 'xxxxxxx'
DEFAULT_FROM_EMAIL = 'xxx.xxx@xxxx'
DEFAULT_TO_EMAIL = 'xxxxx.xxxx@xxxx'

ADMINS = (
    ('XXXX', 'XXXX@xxxxxx'),
)

#SESSION_COOKIE_DOMAIN="http://ec2-xx-xx-xx-xxx.compute-1.amazonaws.com"
SESSION_COOKIE_NAME = 'site2'
#SESSION_COOKIE_PATH =':/tmp'
MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'livedb1',                      # Or path to database file if using sqlite3.
        'USER': 'root',                      # Not used with sqlite3.
        'PASSWORD': 'SMARTDNA',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

# system time zone.
TIME_ZONE = 'Asia/Calcutta'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
if WINDOWS:
  MEDIA_ROOT = ('%s/media/' % (os.path.dirname(__file__))) #'D:/smartDNA/media/'
else:
  MEDIA_ROOT = ('%s/media/' % (os.path.dirname(__file__))) #'/home/ubuntu/server/smartDNA/media/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
if WINDOWS:
  STATIC_ROOT = ('%s/static/' % (os.path.dirname(__file__))) #'D:/smartDNA/static/'
else:
  STATIC_ROOT = ('%s/static/' % (os.path.dirname(__file__))) #'/home/ubuntu/server/smartDNA/static/'

 # STATIC_ROOT = '/home/ubuntu/server/smartDNA/static'

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)


TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request",
    "django.core.context_processors.static",
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
    'djangobower.finders.BowerFinder',
)


# Make this unique, and don't share it with anybody.
SECRET_KEY = '192(q1m!d)k9n)gdq$1d^e7p4%n*3gsbb0waubmuftw)*0lt__'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    #'smartDNA.trackware.UserLocationLoggerMiddleware',
    'pagination.middleware.PaginationMiddleware',
    )

ROOT_URLCONF = 'smartDNA.urls'

if WINDOWS:
  TEMPLATE_DIRS = ('%s/templates' % (os.path.dirname(__file__))) #('D:/smartDNA/templates',)
else:
  TEMPLATE_DIRS = ('%s/templates' % (os.path.dirname(__file__))) #('/home/ubuntu/server/smartDNA/templates',)

INSTALLED_APPS = (
    #'grappelli',
    #'grappelli.dashboard',
    'suit',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'smartDNA.core',
    'googlecharts',
    'pagination',
)

settings.configure()
ADMIN_REORDER = (
    ("core", ("Alert","Verification","AlertSubscriber","Anomaly","Logger","AssetWithPeriodicScanPolicy")),
)
# Django Suit configuration example
SUIT_CONFIG = {
    # header
     'ADMIN_NAME': 'XXXXX RETAIL SECURITY PROGRAMME',
     'HEADER_DATE_FORMAT': 'l, j. F Y',
     'HEADER_TIME_FORMAT': 'H:i',

    # forms
     'SHOW_REQUIRED_ASTERISK': True,  # Default True
     'CONFIRM_UNSAVED_CHANGES': True, # Default True

    # menu
     'SEARCH_URL': '/admin/auth/user/',
     'MENU_ICONS': {
        'sites': 'icon-leaf',
        'auth': 'icon-lock',
        'core': 'icon-globe'
     },
     'MENU_OPEN_FIRST_CHILD': True, # Default True
     'MENU_EXCLUDE': ('auth.group',),
     'MENU': (
         'sites',
         {'app': 'core', 'icon':'icon-globe', 'models': ('Verification', 'Verification')},
         {'app': 'auth', 'icon':'icon-lock', 'models': ('user', 'group')},
         {'label': 'Settings', 'icon':'icon-cog', 'models': ('auth.user', 'auth.group')},
         {'label': 'Support', 'icon':'icon-question-sign', 'url': '/support/'},
     ),

    # misc
     'LIST_PER_PAGE': 15
}

DEBUG_TOOLBAR_CONFIG = {
                'INTERCEPT_REDIRECTS': False,
                    }


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

GEOIP_PATH = "/home/ubuntu/xxxxx/smartDNA/"

Recently my project was running at Django 1.4 but I updated to 1.5 due to some smartbyte encoding error. After that problem started and then I downgraded to Django 1.4. Its not going even after downgrading then I shifted my whole project to new AWS instance (ubuntu 14.04).

I am using Django 1.5 python2.7


Solution

  • settings.configure()
    

    seems to be overriding the privious settings. This must be the key to your problem.

    And in fact, if you call configure() without any arguments, django will use the default settings which normally doesnot have any db engine defined in it, therefore the error you are getting.