33

I have some problems with Django admin.

after syncdb, the result is:

  Creating tables ...
  Installing custom SQL ...
  Installing indexes ...
  No fixtures found.

What does this mean?

Anyway, when I visit the website admin panel http://www.example.com/admin/, I receive this message:

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

setting.py contains:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
)

ur.py contains:

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'rshd.views.home', name='home'),
    # url(r'^rshd/', include('rshd.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
     url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
     url(r'^admin/', include(admin.site.urls)),
)
TRiG
  • 10,148
  • 7
  • 57
  • 107
creative creative
  • 455
  • 1
  • 6
  • 12

10 Answers10

88

You don't really need the sites framework if you only run one site from the project, so the easiest fix would be to remove the following item from your INSTALLED_APPS and the error should go away:

'django.contrib.sites'

You can also re-create the missing Site object from shell. Run python manage.py shell and then:

from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='www.example.com', name='example.com')
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
Ramandeep Singh
  • 5,063
  • 3
  • 28
  • 34
  • 3
    Hey, I had the same issue also. However for me the admin worked before. And suddenly when I check the admin page again it stopped working until I re-created the missing site object. Do you happen to know what the issue is? Why suddenly did I have re-create the missing object? – starcorn Apr 22 '12 at 09:23
  • 16
    If you're using `'django.contrib.sites'`, make sure you've defined `SITE_ID=1` in you settings.py where appropriate. – ramsey0 Jul 29 '15 at 03:49
  • True, Adding the new site in Site Model the database will fix the error. – vivekascoder Jul 30 '21 at 09:32
15

You can fix this error if you are using django.contrib.sites without removing it by changing SITE_ID = 1 value in settings.py file.

It is happen to me when I changed domain name on my server, I deleted old domain name from http://mynewdomainname.com/admin/sites/site/ manually, and the old domain record in database has id = 1, also I added new domain name mynewdomainname.com and it is id was id = 2, I just changed to SITE_ID = 2 and the error gone SITE_ID refers to current "pk" of active domain name you use as default. In code:

>>> from django.contrib.sites.models import Site
>>> # get_current() came from SiteManager class manager, 
>>> # see site-packages/django/contrib/sites/models.py
>>> current_site = Site.objects.get_current()
>>> print(current_site.pk)
2
>>> print(current_site.domain)
'http://mynewdomainname.com'

this happen after settings.py changed

SITE_ID = 2

Be careful about current domain id in django sites app.

Tarek Kalaji
  • 2,149
  • 27
  • 30
3

The same problem also suddenly came to me, and you know there're many solutions. However, what's the reason of this sudden problem?

After dig in deeply, I found the reason is that, we ignored a step in the first syncdb action.

When you have your first syncdb, django will ask you to create a default account, if you don't input in this interactive show, that site object would not be created automatically.

So be careful of this. I'm using django 1.3.1, don't know whether the latest version has resolved this issue.

dphacker
  • 31
  • 2
2

Since the above comments are pretty old and the syncdb command doesn't exist, and I don't want to remove django.contrib.sites, here's what worked for me:

Increment SITE_ID. I had SITE_ID = 1, changed it to SITE_ID = 2 and everything worked again.

Lewy Blue
  • 452
  • 3
  • 16
2

Add SITE_ID = 1 in your settings.py

lwairore
  • 624
  • 1
  • 7
  • 11
1

just fixed the issue by an another way:

I use PostgreSQL and Django 1.45... as i removed the www.example.com Site and added a new www.xxx.com Site it was added as ID=2 'cause PostgreSQL doesn't go back in the ID numbers and the login and logout Django-Sites are somehow bound only to the ID=1 Site in your DB...

I went to my PostgreSQL DB and changed the ID of www.xxx.com to 1 and then I was able to see the login and logout Site again :)

btw. [yes, you just can remove the django.contrib.sites from your settings.py if you don't need it ^^ (but I haven't tried this one out in my case, with the ID number problem)]

hope it will work for further users! ;)

zh0r1k
  • 31
  • 2
  • If that's the case, at least change SITE_ID in your settings.py file instead of editing the db manually. – Atrus Mar 05 '13 at 15:33
0

Yes change the SITE_IT=1 to SITE_ID=2 and everything is ok

0

Yes, the solution mentioned at the top can be (part of) the solution.

I've noticed however, that not only including django.contrib.sites without configuration can cause that problem, also including any site of allauth (pip install django-allauth) might cause this problem if said package is not configured correctly.

(And allauth is as far as I've seen not configured correctly by default...)

delvh
  • 39
  • 2
0

Another thing you can do is simple if you get some error or just want to change site.

  1. Download sqlitebrowser
  2. open your sqlite.db
  3. search for django_sites
  4. change domain name and display name to whatever you want
-2

Check your Window task manager and make sure that there is 1 process name 'python.exe' is running. If there are many, delete all of them then restart the server. This solution works for me.

Tung Linh
  • 79
  • 1
  • 4