簡體   English   中英

Django MongoDB SITE_ID錯誤

[英]Django MongoDB SITE_ID error

嘗試查看管理頁面時出現此錯誤:

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

所以我四處搜尋,發現我需要執行以下操作

 ./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 Shell中查看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', 'your_email@example.com'),
 ...

我在這里做錯了什么?

哦,愚蠢的我。 這些代碼行稍后出現在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' ,現在可以使用了!

我遇到了同樣的問題,但是即使我在settings.py中更改了SITE_ID,問題仍然存在。 我在INSTALLED_APPS中注釋了“ django.contrib.sites”行,然后正確完成了syncdb(在我看來,站點應用程序是一個幾乎沒有人需要的應用程序……如此快速,干凈的解決方案:))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM