Site matching query does not exist

If you don't have a site defined in your database and django wants to reference it, you will need to create one.

From a python manage.py shell :

from django.contrib.sites.models import Site
new_site = Site.objects.create(domain='foo.com', name='foo.com')
print (new_site.id)

Now set that site ID in your settings.py to SITE_ID


Table django_site must contain a row with the same value than id (by default equals to 1), as SITE_ID is set to (inside your settings.py).


Add SITE_ID = 1 to settings.py in your django project.


I fixed it without using python manage.py shell

At first I tried using the commands above using manage.py shell:

from django.contrib.sites.models import Site
new_site = Site.objects.create(domain='foo.com', name='foo.com')
print(new_site.id)

But it gave out an INTEGRITY ERROR

The short answer is add SITE_ID = 1 to your settings.py If you want to know what your site id is, then go into the actual database, I downloaded sqliteman to see what my table had. So whatever site id you have in the table is what gets assigned to SITE_ID

This is because there is a function get_current that goes looking for SITE_ID and it doesn't find it in your settings.py

tables
-django_site
--Columns
---id

it should have id as 1, name as example.com, domain as example.com