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 mess
In addition to Simeon Visser's answer for those of you still experiencing problems, make sure the SITE_ID
variable in your settings matches the ID of your newly created Site
-object.
comment out django.contrib.sites from the installed apps. i.e.
#'django.contrib.sites',
I was also struggling with the same error for quite some time now. I had by mistake deleted the example.com from sites directory in admin. Once I added the site using above solutions, it worked. Also site_id automatically became 2 when I created the example.com and so had to change site_id to 2 in my settings file also. Thank you.
If you use South and initial_data fixtures, data could be loaded not properly. To fix it add
if 'test' in sys.argv or 'jenkins' in sys.argv:
SOUTH_TESTS_MIGRATE = False
at the end of your settings file
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 reran syncdb
, the missing django tables were created, and the django_site
DB table was populated with id=1, domain=example.com, name=example.com. Evidently the Site
class is backed by the django_site
DB table. Now I understand the problem and the solution above that populated the table using the Site.objects.create()
method. Thanks Simeon.
Sometimes if you add more Sites via Admin and delete some of them each site has an ID, it was not working for me once I changed the ID in the DB it started working, so make sure SITE_ID matches the ID in the database.