Django MongoDB Engine Error on Telliteid Startup

SO I created the django project and application according to the tutorial, and I have all the dependencies needed for the MongoDB Engine, it all seemed to work fine and dandy until I tried to enable the admin interface.

I split the necessary bits and added "django_mongodb_engine" and "djangotoolbox" to the application section in settings.py

When I try to get to localhost: 8000 / admin, I get the error message:

"The AutoField values ​​(default primary key) should be strings representing the ObjectId on MongoDB (u'1 instead). Make sure your SITE_ID contains a valid ObjectId string."

After some googling, apparently I need to run manage.py tellsiteid, and it will spit out an identifier for me, which I can use in my .py settings, which will make the error go away, but when I try to run manage.py tellsiteid I get:

Traceback (most recent call last): File "./manage.py", line 14, in <module> execute_manager(settings) File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site- packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute() File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv self.execute(*args, **options.__dict__) File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute output = self.handle(*args, **options) File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle return self.handle_noargs(**options) File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django_mongodb_engine/management/commands/tellsiteid.py", line 8, in handle_noargs site_id = self._get_site_id() File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django_mongodb_engine/management/commands/tellsiteid.py", line 19, in _get_site_id return Site.objects.get().id File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/db/models/manager.py", line 132, in get return self.get_query_set().get(*args, **kwargs) File "/Users/holografix/.virtualenvs/django_nonrel_env/lib/python2.7/site-packages/django/db/models/query.py", line 351, in get % self.model._meta.object_name) django.contrib.sites.models.DoesNotExist: Site matching query does not exist. 
+6
source share
9 answers

You have not created a site yet. Run manage.py syncdb to create it.

+5
source

You can create your site and then get the identifier:

 python ./manage.py shell >>> from django.contrib.sites.models import Site >>> s = Site() >>> s.save() 

and then:

 python ./manage.py tellsiteid 
+12
source

If you do not need the functionality of sites (which is very likely), just disable the django.contrib.sites application and it will fix the MongoDB problems associated with SITE_ID:

 INSTALLED_APPS = ( (...) # 'django.contrib.sites', # Comment this out (...) ) 
+12
source

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

Capturing the identifier from the shell worked for me, more details here:

https://gist.github.com/ielshareef/2986459 or are requests to the appropriate site 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 it worked fine!

+3
source

I ran into this during my setup the other day.

Basically, you need to place the logo in the mongo shell and find your site, and then add its settings.py

go into the mongo shell

 mongo 

choose your db

 use *name* 

then find find () on django_site

 db.django_site.find() 

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

 SITE_ID = u'4f1f82011d41c81e5c00001d' 

This should make you work and work.

+2
source

Most likely, you have not yet created a site, for this you need to run the command

 python manage.py syncdb 

This creates the site, now you need to add its site_id to your settings file. Go, get the site ID, connect to the 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. It?

+2
source

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

I will finally resolve it by dropping the database and synchronizing again.

Hope this can help someone :)

0
source

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 '

0
source

Source: https://habr.com/ru/post/905707/


All Articles