ValueError:相关模型u' app.model'运行测试时无法解决

时间:2017-10-01 11:32:39

标签: python django testing valueerror

我正在尝试在Django项目上运行一些测试(Django版本1.11.4) 使用Python 3.5.0。

我的项目中有2个应用程序:uploads和testgen。

这些是我的模特:

(这里只有特殊字段,比如关系字段。其余字段主要是CharField,PositiveIntegerField和BooleanField。)

上传\ models.py

(简化版)

class Document(models.Model):
    (any relationship fields)


class Word(models.Model):
    synonyms = models.ManyToManyField("self")
    antonyms = models.ManyToManyField("self")


class Sentence(models.Model):
    words = models.ManyToManyField(Word)


class Paragraph(models.Model):
    sentences = models.ManyToManyField(Sentence)


class Text(models.Model):
    document = models.ForeignKey(Document, on_delete=models.CASCADE)
    paragraphs = models.ManyToManyField(Paragraph)

testgen \ models.py

(简化版)

class Issue(models.Model):
    content = models.OneToOneField(Sentence,
                                   related_name="issue_content",
                                   null=True)
    question = models.OneToOneField(Sentence, null=True)


class FillableIssue(Issue):
    replaceable_words = models.ManyToManyField(Word)


class StatementIssue(Issue):
    replaceable_words = models.ManyToManyField(Word)


class AppTest(models.Model):
    text = models.ForeignKey(Text, null=True)
    fillable_issues = models.ManyToManyField(FillableIssue)
    statement_issues = models.ManyToManyField(StatementIssue)

testgen \ tests.py

from django.test import TestCase
from testgen.models import AppTest


class AppTestTestCase(TestCase):

    def test_apptest_has_positive_number_issues(self):

        """
            has_positive_number_issues() returns True
            if the test's number issues is greater than zero.
        """

        app_tests = AppTest.objects.get_queryset().all()
        for app_test in app_tests:
            self.assertIs(app_test.has_positive_number_issues(), True)

项目设置文件:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'uploads',
'testgen',
]

注意:我使用testgen模型中的上传模型作为应用程序逻辑。

我怀疑该模型的名称可能是问题(' AppTest')

可以在屏幕截图图像中检查回溯。

first capture second capture

1 个答案:

答案 0 :(得分:1)

我已从其他应用中删除了所有迁移文件并运行makemigrations并再次迁移。

现在一切正常。