I am getting this error when trying to view the admin page:
InvalidId at /admin/
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.
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.3
Exception Type: InvalidId
Exception Value:
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.
...
So I googled around and figured that I needed to do the following
./manage.py tellsiteid
The default site's ID is u'50c5766e62f11f41f0332e65'. To use the sites framework, add this line to settings.py:
SITE_ID=u'50c5766e62f11f41f0332e65'
So I added it to my settings.py
:
DEBUG = True
TEMPLATE_DEBUG = DEBUG
SITE_ID = u'50c5766e62f11f41f0332e65'
...
I still get that same error message. Am I supposed to run a syncdb
or restart the server? Because I've done both and am still getting the same error.
EDIT
I've tried viewing the value of SITE_ID
in the Python shell, and sure enough...
$ python manage.py shell
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from concepts.settings import *
>>> SITE_ID
1
But git diff
clearly shows that I have changed the settings file, right?
$ git diff
diff --git a/settings.py b/settings.py
index 586ea3a..bb069ed 100644
--- a/settings.py
+++ b/settings.py
@@ -2,6 +2,7 @@
DEBUG = True
TEMPLATE_DEBUG = DEBUG
+SITE_ID = u'50c5766e62f11f41f0332e65'
ADMINS = (
# ('Your Name', 'your_email@example.com'),
...
What am I doing wrong here?
Ohhhh silly me. These lines of code appeared later in settings.py
:
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
...
So I simply changed the 1 there to u'50c5766e62f11f41f0332e65'
and now it works!
I had the same problem but even when I changed SITE_ID in my settings.py the problem remained. I commented the line 'django.contrib.sites' in INSTALLED_APPS and syncdb finished then properly (the sites application seems to me as an application that almost nobody would need...so quick and clean solution :))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.