我有一个模型
class Survey(models.Model):
created_by = models.ForeignKey(User)
question = models.CharField(max_length=150)
active = models.NullBooleanField()
def __unicode__(self):
return self.question
现在我只想更新该active
字段。所以我这样做:
survey = get_object_or_404(Survey, created_by=request.user, pk=question_id)
survey.active = True
survey.save(["active"])
现在我得到一个错误IntegrityError: PRIMARY KEY must be unique
。
我对这种方法进行更新是否正确?