Django admin DoesNotExist at /admin/

The same problem also suddenly came to me, and you know there're many solutions. However, what's the reason of this sudden problem?

After dig in deeply, I found the reason is that, we ignored a step in the first syncdb action.

When you have your first syncdb, django will ask you to create a default account, if you don't input in this interactive show, that site object would not be created automatically.

So be careful of this. I'm using django 1.3.1, don't know whether the latest version has resolved this issue.


You can fix this error if you are using django.contrib.sites without removing it by changing SITE_ID = 1 value in settings.py file.

It is happen to me when I changed domain name on my server, I deleted old domain name from http://mynewdomainname.com/admin/sites/site/ manually, and the old domain record in database has id = 1, also I added new domain name mynewdomainname.com and it is id was id = 2, I just changed to SITE_ID = 2 and the error gone SITE_ID refers to current "pk" of active domain name you use as default. In code:

>>> from django.contrib.sites.models import Site
>>> # get_current() came from SiteManager class manager, 
>>> # see site-packages/django/contrib/sites/models.py
>>> current_site = Site.objects.get_current()
>>> print(current_site.pk)
2
>>> print(current_site.domain)
'http://mynewdomainname.com'

this happen after settings.py changed

SITE_ID = 2

Be careful about current domain id in django sites app.


You don't really need the sites framework if you only run one site from the project, so the easiest fix would be to remove the following item from your INSTALLED_APPS and the error should go away:

'django.contrib.sites'

You can also re-create the missing Site object from shell. Run python manage.py shell and then:

from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='www.example.com', name='example.com')

Tags:

Django