Upgrading Django 1.1.1 to 1.3.1, admin.autodiscover() raises exception asking for contenttypes

742 Views Asked by At

I switched a 1.1.1 Django project to 1.3.1. Upon calling admin.autodiscover() in urls.py, an exception is raised from sites.py in the admin framework stating:

ImproperlyConfigured at /
Put 'django.contrib.contenttypes' in your INSTALLED_APPS setting in order 
to use the admin application

In settings.py, I have:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'my.app'
)

Things I checked:

  1. The contenttypes framework is indeed in my INSTALLED_APPS setting.
  2. I have not repeated my INSTALLED_APPS declaration anywhere else
  3. The contenttypes entry in INSTALLED_APPS is listed before the admin entry.
  4. Running django-admin.py shell and importing "django.contrib.contenttypes" works.

If I go to the offending lines in the admin (Django-1.3.1/django/contrib/admin/sites.py in check_dependencies, line 164), I see:

if not ContentType._meta.installed:
    raise ImproperlyConfigured(...)

If I comment out the check, I can run my project and the admin works. I'm not sure how the _meta.installed property is supposed to be set on model types, so I am at a loss for what to do next.

I should also note that this same Django 1.3.1 installation is working with other projects using similar settings files.

Any hints or resources would be appreciated! Thanks!

1

There are 1 best solutions below

0
On

django.contrib.contenttypes includes two models, ContentType and ContentTypeManager. My guess is that you haven't run manage.py syncdb after adding django.contrib.contenttypes to your INSTALLED_APPS.

This would make the if not ContentType._meta.installed check understandable: the ContentType model isn't available in the database yet.