ValueError: Related model u'app.model' cannot be resolved when running tests

ValueError: Related model u'app.model' cannot be resolved when running tests

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

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

这些是我的模型:

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

uploads\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

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

现在一切正常。