Django测试生成CommandError:x与模型y有关系,模型y未安装或是抽象的

时间:2014-03-31 15:42:20

标签: python django

当我运行导入我的django应用程序之一的测试时出现以下错误,该应用程序被称为“民意调查”,

CommandError: One or more models did not validate:
vote.vote: 'polls' has a relation with model polls.Vote, which has either not been installed or is abstract.
vote.vote: 'questions' has an m2m relation with model polls.Questions, which has either not been installed or is abstract.

民意调查app模型的结构不是polls / models.py,而是

polls/
  models/
    __init__.py
    polls.py
    polls_stuff.py

在polls.py/polls_stuff.py中,我的模型定义如此,

class Polls(models.Model):
    # fields...
    class Meta:
        app_label = 'polls'

(在民意调查/ models / __ init __ .py我导入所有模型类)

似乎django test命令在模型组织在它们自己的目录中时遇到问题,而不是在models.py文件中定义模型,而该模型是主运行文件。但是,我通过在民意调查应用程序中运行测试或导入民意调查模型的测试来获取CommandErrors。但常规的应用程序使用非常顺利..

任何人都知道我如何解决这个问题,并保留我的模型目录,而不是将我的模型定义重构为一个大型的.stat文件......

注意:我正在使用django 1.6& python 3 ..

0 个答案:

没有答案
相关问题