我正在尝试通过外键将模型Post链接到模型Topic 。当我运行 makemigrations 命令时,它会引发导入错误,并说未定义名称“主题”。这可能是什么原因?它似乎确实被定义了。我几乎排除了这不是数据库中的问题。
class Post(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True)
title = models.CharField(max_length=100)
summary = models.TextField(blank=True, null=True)
content = models.TextField()
draft = models.BooleanField(default=False)
details = models.CharField(blank=True, null=True, max_length=250)
updated = models.DateTimeField(auto_now=True, auto_now_add=False)
timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
topic = models.ForeignKey(Topic, blank=True, null=True)
thumbnail = models.ImageField(upload_to='media', blank=True, null=True)
def get_absolute_url(self):
return reverse('posts:detail', kwargs={'pk': self.pk})
def __str__(self):
return self.title
class Topic(models.Model):
name = models.CharField(max_length=50)
description = models.TextField()
picture = models.ImageField(upload_to='media', blank=True, null=True)
isperson = models.BooleanField(default=False)
ispolicy = models.BooleanField(default=False)
positive = models.BooleanField(default=True)
percent = models.CharField(max_length=5)
def __str__(self):
return self.name
有任何想法吗?我在这段代码中没有看到任何问题,我的 IDE 也没有,它识别了模型Topic