我有个模特
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
。
我用这种方法更新对吗?