Questions tagged «django-database»

2
仅更新模型中的特定字段。
我有一个模特 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。 我可以用这种方法更新吗?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.