[Django]-How to fix the django_sites table?

58πŸ‘

βœ…

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='mdev.5buckchuck.com', name='5buckchuck.com')

8πŸ‘

Provide SITE_ID=1 in settings.py. This will work.

πŸ‘€vikas0713

1πŸ‘

I went through this problem too, while playing with django-allauth. The application offers the ability to delete sites. If you delete the one designated by the SITE_ID parameter in settings.py, you’ll have to point the correct PK of another valid site.

If you deleted the default site example.com(changes are you did some cleanup after adding another site), you may simply want to select the other site you created by setting SITE_ID to 2 for example. If you work with SQL database, look for the django_site table, and locate the site ID you wish to work with.

This way, no need to go into shell and recreating a not necessary desired site.

πŸ‘€user1826252

0πŸ‘

If you need sites, you can use data fixtures. Read the docs for tip about enabling the sites framework.

πŸ‘€kbec

Leave a comment