SO I created a django project and app as per the tutorial and I have all the dependencies necessarry for MongoDB Engine it all seemed to be working fine and dandy till I tried enabling the admin interface.
I uncommented the require bits, and added 'django_mongodb_engine' and 'djangotoolbox' to the apps section in settings.py
When I try to get into localhost:8000/admin I get an error:
"AutoField (default primary key) values must be strings representing an ObjectId on MongoDB (got u'1' instead). Please make sure your SITE_ID contains a valid ObjectId string."
After some googling apparently I have to run manage.py tellsiteid and it'll spit me an ID I can use within my settings.py that 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.
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
(...)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With