Python 遵循Django官方教程第2部分,makemigrations问题,没有得到添加字段问题的选择

Python 遵循Django官方教程第2部分,makemigrations问题,没有得到添加字段问题的选择,python,django,model,migration,Python,Django,Model,Migration,在编辑models.py后尝试进行迁移时,我被Django官方教程的第2部分卡住了。 我只有这两行: /mysite$python manage.py makemigrations轮询 “轮询”的迁移: 轮询/迁移/0001_initial.py -创建模型问题 -创建模型选择 Missing“-AddFieldQuestiontoChoice”,当我试图在Pythonshell中添加选项时,这会导致问题。 我一直在复制大部分代码,但是,my models.py目前已恢复到: from Djan

在编辑models.py后尝试进行迁移时,我被Django官方教程的第2部分卡住了。 我只有这两行: /mysite$python manage.py makemigrations轮询 “轮询”的迁移: 轮询/迁移/0001_initial.py -创建模型问题 -创建模型选择

Missing“-AddFieldQuestiontoChoice”,当我试图在Pythonshell中添加选项时,这会导致问题。 我一直在复制大部分代码,但是,my models.py目前已恢复到:

from Django.DB import models      

class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')


class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
有什么我可以做错事不得到这个“-添加领域问题的选择”? 后来,当我试图将第一选择添加到该问题时,控制台告诉我:

>>> q = Question.objects.get(pk=1)
>>> q
<Question: What's up?>
>>> q.choice_set.all()
<QuerySet []>
>>> q.choice_set.create(choice_text='Not much', votes=0)
Traceback (most recent call last):
  File "/usr/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/home/rufus/.local/lib/python3.6/site-        
packages/django/db/models/base.py", line 519, in __repr__
return '<%s: %s>' % (self.__class__.__name__, self)
  File "/home/rufus/mysite/polls/models.py", line 19, in __str__
return self.question_text
  AttributeError: 'Choice' object has no attribute 'question_text'
>>> q
<Question: What's up?>`
q=Question.objects.get(pk=1) >>>q ` 我应该编辑models.py还是这里出了问题?请帮忙


我尝试更改models.py并执行makemigrations和migrate,但没有任何更改。

第一个不是问题,只是教程中的一个旧参考。第二个原因是您将
question\u text
放在
\u str\u\u
选择方法中,而不是
Choice\u text
。谢谢,我以后会更加小心。第一个不是问题,只是教程中的一个老参考。第二个原因是你把
question\u text
放在
\u str\u
选择方法中,而不是
Choice\u text
。谢谢你,我以后会更加小心。