Django MongoDB Engine error when running tellsiteid

浪尽此生 提交于 2019-12-02 19:47:57

You haven't created any Site yet. Run manage.py syncdb to create one.

You can create your site, and then, get the id:

python ./manage.py shell

>>> from django.contrib.sites.models import Site
>>> s = Site()
>>> s.save()

and then:

python ./manage.py tellsiteid

If you do not need the sites functionality (which is very probable) simply turn off django.contrib.sites app and it will fix MongoDB issues related to the SITE_ID:

INSTALLED_APPS = (   
    (...)
    # 'django.contrib.sites',  # Comment this out
    (...)
)
DharmaTurtle

For some reason none of the solutions here worked for me. python ./manage.py tellsiteid, there was no django_site collection, and commenting out 'django.contrib.sites' caused weird errors.

Grabbing the ID from the shell worked for me though, detailed here:

https://gist.github.com/ielshareef/2986459 or here Site matching query does not exist

python ./manage.py shell
>>> from django.contrib.sites.models import Site
>>> Site().save()
>>> Site.objects.all()[0].id
u'4fe7aa759e654e2662000000'

Put it in settings.py and everything worked great!

I ran into this during my setup the other day.

Basically you need to logo into a mongo shell and lookup your siteid then add it your settings.py

log into a mongo shell

mongo

select your db

use *name*

then do a find() on django_site

db.django_site.find()

Then open your settings.py and edit the site_ID ="" line (mine is below)

SITE_ID = u'4f1f82011d41c81e5c00001d'

That should get you up and running

Most likely you havent created a site yet, to do so you need to run the command

python manage.py syncdb

This creates the site, now you need to add its site_id in your settings file. Go get the site id, connect to mongodb engine that is running, and run the following commands

use mydatabase --/# or whatever name you have for your database.
db.django_site.find()

you will get something like

ObjectId("4f4e968adea3b3b30c00001d")

then in your settings file, put

site_id = u'4f4e968adea3b3b30c00001d'

and the admin interface should work. Does it?

I use manage.py syncdb and then manage.py tellsiteid but still display error.

I finally solve it by dropping the database and sync again.

Hope this can help someone:)

sudo python manage.py shell

from django.contrib.sites.models import Site
Site().save()
Site.objects.all()[0].id
u'53aa6456984edd0d5e547e03'

Put it in settings.py SITE_ID = u'53aa6456984edd0d5e547e03'

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!