2

管理ページを表示しようとすると、次のエラーが表示されます。

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または再起動する必要がありますか? 私は両方を行ったが、まだ同じエラーが発生しているためです。

編集

SITE_IDPythonシェルでの値を表示しようとしましたが、確かに...

$ 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'),
 ...

ここで何が間違っていますか?

4

2 に答える 2

5

ああ、ばかげている。これらのコード行は後で登場しました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'で、機能するようになりました。

于 2012-12-10T08:05:18.080 に答える