2012-12-10 40 views
2

我正在試圖查看管理頁面時,這個錯誤:的Django MongoDB的SITE_ID錯誤

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. 
... 

所以我用Google搜索周圍,計算過,我需要做下面的

./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' 

所以我添加它給我settings.py

DEBUG = True 
TEMPLATE_DEBUG = DEBUG 
SITE_ID = u'50c5766e62f11f41f0332e65' 
... 

我仍然得到相同的錯誤消息。我應該運行一個syncdb還是重新啓動服務器?因爲我已經完成了這兩項工作,並且仍然遇到同樣的錯誤。

編輯

我試着在Python外殼觀看的SITE_ID價值,果然...

$ 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 

git diff清楚地表明,我已經改變了設置文件,對?

$ 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', '[email protected]'), 
... 

我在做什麼錯在這裏?

回答

5

Ohhhh傻我。這些代碼行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 
... 

所以我只是改變了1那裏u'50c5766e62f11f41f0332e65'和現在的作品!

0

我有同樣的問題,但即使我改變了我的settings.py SITE_ID問題仍然存在。我評論了INSTALLED_APPS和syncdb中的'django.contrib.sites'這一行,然後正確地完成了(網站應用程序在我看來應該是幾乎沒有人需要的應用程序......所以快速而乾淨的解決方案:))