我一直很难在 Python2.5 上使用 syncdb 构建数据库。我认为这个问题的一部分是因为使用通配符* 导入 forum.models 它似乎正在创建一个循环。
>>> import settings
>>> from forum.managers import QuestionManager, TagManager, AnswerManager, VoteManager, FlaggedItemManager, ReputeManager, AwardManager
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/username/webapps/username/sousvide_app/forum/managers.py", line 6, in <module>
from forum.models import *
File "/home/username/webapps/username/sousvide_app/forum/models.py", line 18, in <module>
from forum.managers import QuestionManager, TagManager, AnswerManager, VoteManager, FlaggedItemManager, ReputeManager, AwardManager
ImportError: cannot import name QuestionManager
>>> from forum.models import Question, Tag
>>> from forum.managers import QuestionManager, TagManager, AnswerManager, VoteManager, FlaggedItemManager, ReputeManager, AwardManager
>>> import sys, pprint
>>> pprint.pprint(sys.path)
['/home/username/webapps/username/sousvide_app',
'/home/username/webapps/username/lib/python2.5',
'/home/username/lib/python2.5/markdown2-1.0.1.16-py2.5.egg',
'/home/username/lib/python2.5/html5lib-0.11.1-py2.5.egg',
'/home/username/lib/python2.5',
'/usr/local/lib/python25.zip',
'/usr/local/lib/python2.5',
'/usr/local/lib/python2.5/plat-linux2',
'/usr/local/lib/python2.5/lib-tk',
'/usr/local/lib/python2.5/lib-dynload',
'/usr/local/lib/python2.5/site-packages',
'/usr/local/lib/python2.5/site-packages/PIL']
>>> from settings import INSTALLED_APPS
>>> pprint.pprint(INSTALLED_APPS)
('sousvide_app.forum',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.humanize',
'django_authopenid')
我在另一个安装中遇到了同样的问题,我可以通过从 forum.managers 显式导入管理器来解决这个问题。
如您所见,如果我将 Question 和 Tag 模型加载到命名空间中,我就可以在 shell 中导入管理器。
我做了 from forum.models import * 明确:
from forum.models import Question, Tag
但是,我仍然无法同步数据库。当我尝试输出 SQL 时,找不到 APP。
$ python2.5 manage.py sql forum
错误:找不到带有标签论坛的应用程序。您确定您的 INSTALLED_APPS 设置正确吗?
谁能给我一个想法是怎么回事?
Python2.5 是否有可能导致此错误的原因?