Getting Site Matching Query Does Not Exist Error after creating django admin

后端 未结 12 2114
后悔当初
后悔当初 2020-12-07 15:05

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

相关标签:
12条回答
  • 2020-12-07 15:19

    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.

    0 讨论(0)
  • 2020-12-07 15:21

    comment out django.contrib.sites from the installed apps. i.e.

    #'django.contrib.sites',
    
    0 讨论(0)
  • 2020-12-07 15:25

    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.

    0 讨论(0)
  • 2020-12-07 15:26

    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

    0 讨论(0)
  • 2020-12-07 15:30

    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.

    0 讨论(0)
  • 2020-12-07 15:31

    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.

    0 讨论(0)
提交回复
热议问题