25

I have just installed my Django project on a new system, and installed Django 1.4. However when I try to run manage.py runserver or manage.py syncdb I get this error from South:

Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1a67810>>
Traceback (most recent call last):
  File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
    self.validate(display_num_errors=True)
  File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
    num_errors = get_validation_errors(s, app)
  File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/django/core/management/validation.py", line 30, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/django/db/models/loading.py", line 158, in get_app_errors
    self._populate()
  File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/django/db/models/loading.py", line 64, in _populate
    self.load_app(app_name, True)
  File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/django/db/models/loading.py", line 88, in load_app
    models = import_module('.models', app_name)
  File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/south/models.py", line 2, in <module>
    from south.db import DEFAULT_DB_ALIAS
  File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/south/db/__init__.py", line 78, in <module>
    db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'

I am using SQlite currently. I think it might be because of this change with Django 1.4, however other users don't seem to having my problem. All my packages are up to date.

3 Answers 3

41

I have the same error message but with a different cause and solution compared to the accepted answer. The short answer is adding SOUTH_DATABASE_ADAPTERS = {'default':'south.db.postgresql_psycopg2'} to settings.py.

Here is the full explanation:

Tracing to south/db/__init__.py shows that no database was detected, the reason being that my database engine name is not in the hardcoded list in south/db/__init__.py

engine_modules = {
    'django.db.backends.postgresql_psycopg2': 'postgresql_psycopg2',
    'django.db.backends.sqlite3': 'sqlite3',
    'django.db.backends.mysql': 'mysql',
    'django.db.backends.oracle': 'oracle',
    'sql_server.pyodbc': 'sql_server.pyodbc', #django-pyodbc
    'sqlserver_ado': 'sql_server.pyodbc', #django-mssql
    'firebird': 'firebird', #django-firebird
    'django.contrib.gis.db.backends.postgis': 'postgresql_psycopg2',
    'django.contrib.gis.db.backends.spatialite': 'sqlite3',
    'django.contrib.gis.db.backends.mysql': 'mysql',
    'django.contrib.gis.db.backends.oracle': 'oracle',
    'doj.backends.zxjdbc.postgresql': 'postgresql_psycopg2', #django-jython
    'doj.backends.zxjdbc.mysql': 'mysql', #django-jython
    'doj.backends.zxjdbc.oracle': 'oracle', #django-jython
}

I use postgis 2.0 on Windows and a while ago had to apply a minor patch to django's postgis backend. Because I didn't install django from source, I made a copy of the backend and applied the patch manually to that copy. So the new backend is in a different location, and that location isn't in the list of keys in South's engine_modules shown above.

Luckily, South provides a settings variable called SOUTH_DATABASE_ADAPTERS that tells South directly the actual database engine of each alias. I was able to run syncdb after inserting this line into settings.py

SOUTH_DATABASE_ADAPTERS = {'default':'south.db.postgresql_psycopg2'}

2
  • 8
    Worked for me, in my case I have 'ENGINE': 'mysql.connector.django' in DATABASES and SOUTH_DATABASE_ADAPTERS = { 'default' : 'south.db.mysql' } for South. MySQL 5.6 Commented Oct 6, 2013 at 9:37
  • Thanks for all the money, @Kevin. Now I'm rich!! Commented May 29, 2015 at 20:13
20

You don't have correct DATABASES in your settings. There should be a database named 'default'

4
  • Thank you, I forgot that I was checking my hostname to use local settings, and my hostname was changed with my new system, so that my database was not set. Commented Apr 8, 2012 at 5:47
  • 1
    I am getting the same error. Can you elaborate the solution. Thanks @saul.shanabrook Commented Jan 18, 2013 at 19:21
  • 2
    Please follow the link provided, there is a minimal working example in the docs
    – ilvar
    Commented Feb 1, 2013 at 13:43
  • Can you help me out I am using jython, so I can't use a default DB connector for postgresql. Commented Sep 7, 2014 at 23:55
4

For those using Heroku, which is my case. I found this problem too, I have the default database set, as they point out in the heroku guides:

DATABASES['default'] =  dj_database_url.config()

However, the ketError 'default' error still appears. This is due to there is no database provisioned, and thus dj_database_url cannot find it and raised that confusing error.

To solve it just provision the database and promote it as explained in heroku postgresql

heroku addons:add heroku-postgresql:dev
heroku pg:promote HEROKU_POSTGRESQL_BLUE

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.