[Django]-Why does removing 'django.contrib.sites' from INSTALLED_APPS fix the 'DoesNotExist at /admin/' error that I suddenly got?

7👍

You need a Site object to be present in the sites table. For some reason, the Site object was not created.

Try this

Log into your django shell

$> ./manage.py shell
>>> from django.contrib.sites.models import Site
>>> site = Site()
>>> site.domain = 'example.com'
>>> site.name = 'example.com'
>>> site.save()

OR

$> ./manage.py shell
>>> from django.contrib.sites.models import Site
>>> site = Site.objects.create(domain='example.com', name='example.com')
>>> site.save()

This should fix your problem.

You could also refer to this documentation about enabling the Sites framework:

To enable the sites framework, follow these steps:

  • Add ‘django.contrib.sites’ to your INSTALLED_APPS setting.

  • Define a SITE_ID setting:

    SITE_ID = 1

  • Run migrate.

django.contrib.sites registers a post_migrate signal handler which creates a default site named example.com with the domain example.com. This site will also be created after Django creates the test database. To set the correct name and domain for your project, you can use an initial data fixture.

Leave a comment