I'm going through the standard Django tutorial to create an admin for an app. After commenting the admin related stuff in settings and running syncdb I'm getting this message:
DoesNotExist at /admin/ Site matching query does not exist.
Can anyone help me figure this out?
When you include the django.contrib.sites to your INSTALLED_APPS and run the command "python manage.py migrate" the app automatically creates a object into "django_site" table (with domain name and display name equals to "example.com". There is no need to create it by yourself.
Probably you just need to add the setting SITE_ID = 1 to your settings.py file.
comment out django.contrib.sites from the installed apps. i.e.
The
Site
object for your Django project is missing. Each Django project has aSite
object which contains the site's name and domain. It is usually automatically created when creating a Django project (in particular, when thesyncdb
command runs) but in your case it seems that didn't happen.To fix it:
Open the Django shell for your site (
python manage.py shell
).Type the following:
If you want to change these values later, go to your admin panel (
/admin/
) and edit the site object in the sectionSites
.If you already have example.com in your sites table after you run
You need to get id of this entry.
To get the ID you can do -
Get the id you get here into
setting.py
. Eg.Basically ID in table corresponding yo tour site and in the settings.py should match.
I'm a Django newbie. I got the same error when going through the tutorial. My
django_site
DB table was empty. I chose to drop all tables named "django_*". Then when I reransyncdb
, the missing django tables were created, and thedjango_site
DB table was populated with id=1, domain=example.com, name=example.com. Evidently theSite
class is backed by thedjango_site
DB table. Now I understand the problem and the solution above that populated the table using theSite.objects.create()
method. Thanks Simeon.You could also consider of using fixture feature of django to populate the data automatically: https://docs.djangoproject.com/en/dev/howto/initial-data/