代码:
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_time = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
错误:
解决办法:
将第十二行的代码改为:
question = models.ForeignKey(Question, on_delete=models.CASCADE,)
即在外键值的后面加上 on_delete=models.CASCADE