嗨,当我尝试将此评论插入我的 MTTP 时,我收到此错误。我正在使用 MTTP 而不是 MTTP-Comments。请帮忙!
IntegrityError at /tasks/3264/
(1452, 'Cannot add or update a child row: a foreign key constraint fails
(`taskdb`.`tasks_comment`, CONSTRAINT `task_id_refs_id_1c5648d2` FOREIGN KEY
(`task_id`) REFERENCES `tasks_task` (`id`))')
我的模型是:
class Task(models.Model):
class Meta:
app_label = 'tasks'
ordering = ('taskid',)
# meta
taskid = models.IntegerField(default=0, db_index=True)
def __unicode__(self):
return u'%s' % self.taskid
class Comment(MPTTModel):
task = models.ForeignKey(Task)
author = models.CharField(max_length=60)
comment = models.TextField()
added = models.DateTimeField(default=datetime.now)
# a link to comment that is being replied, if one exists
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
class MPTTMeta:
order_insertion_by=['added']
我的看法是:
if request.POST:
comment = Comment(
author=request.POST['author'],
comment=request.POST['comment'],
task_id='3264',
)
comment.save()
我的 HTML 是:
<form action="" method="post">
<input type="text" value="" name="author">
<textarea name="comment"></textarea>
<input type="submit" value="Add comment"> </form>