2

我收到错误消息:

在表“quizzer_progress”上插入或更新违反了外键约束。详细信息:表“quizzer_alone_words”中不存在键 (word_id)=(4700)。

但这没有任何意义。我在models.py中有这3个表:

class Progress(models.Model):
  success = models.IntegerField(default=0)
  fail = models.IntegerField(default=0)
  total = models.IntegerField(default=0)
  word = models.ForeignKey(Word, related_name='word_progress', blank=True, null=True)

class WordLesson(models.Model):
  text = models.CharField(max_length=3000, blank=True)
  owner = models.ForeignKey(User, related_name='Words_from_lessons')
  words = models.ManyToManyField('Alone_Words', blank=True)
  min_age = models.IntegerField(default=0)
  max_age = models.IntegerField(default=0)

class Alone_Words(models.Model):
  lesson = models.ForeignKey(WordLesson, related_name='lesson_of_the_word', blank=True, default=1)
  word = models.CharField(max_length=100, blank=True)
  position = models.IntegerField(default=0)

如您所见,我试图保存数据的表与“违反外键约束”的表无关

谁能告诉我这是怎么回事???

注意:失败的代码是这个->

p = Progress(success =0,fail = 0,total =0,word = myword)
p.save()
4

0 回答 0