# 在ORM中设置自关联字段 class Comment(models.Model): user = models.ForeignKey(to='UserInfo') article = models.ForeignKey(to='Article') content = models.CharField(max_length=255) create_time = models.DateField(auto_now_add=True) parent = models.ForeignKey(to='self', null=True) 注意:自关联,关联的是当前表的主键ID字段!!!! 上表中parent对应的是Comment.pk. 切记,若关联错误,则会查询出错.