[Solved] Django project /admin Site matching query does not exist

I am running a site live on heroku. My issuse occurs when I visit my site’s admin located at www.mysite.com/admin. When I visit this page, I get

DoesNotExist at /admin/
Site matching query does not exist.

Thing is, my project /admin works locally as well as on my staging server. It just so happens when I visit it live, I get that error.

After looking around SOF, I tried doing running python manage.py shell with the following commands:

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

and I changed SITE_ID = 1 to SITE_ID = www.mysite.com and that just ended up breaking my staging server, so I changed it back and tried again without changing the SITE_ID.

What could be the issue?

Solution #1:

It seems the SITE_ID setting in your settings file is pointing to an ID that doesn’t exist in your database.

You either need to create a new site in the sites model (via admin) and change the ID in the settings file to match that one, or re-insert the item via SQL and give it the same ID as your settings file.

Respondent: Llanilek

Solution #2:

This problem will always seem to occur continually, so if you don’t want to serve your model with multiple sites, then I suggest you remove the SITE_ID from the setting file. Note this worked for me!

Respondent: Okayjosh

Solution #3:

I just had to remove the 'django.contrib.sessions' from INSTALLED_APPS in settings.py as it was causing problems and I was using this project only for one site.

However, if you are using your project for multiple different sites and need the Django sites framework, please check SITE_ID in your database and if it matches the one defined in the settings.

Respondent: PrimozKocevar

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.