# Update fields in Viewsets and Mixins

**URL:** <https://forum.djangoproject.com/t/update-fields-in-viewsets-and-mixins/9903>\
**Category:** Using Django\
**Created:** [September 29, 2021, 9:13am UTC](https://forum.djangoproject.com/t/update-fields-in-viewsets-and-mixins/9903 "2021-09-29T09:13:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![uwaiszaki104](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/uwaiszaki104/32/5951_2.png) [@uwaiszaki104](https://forum.djangoproject.com/u/uwaiszaki104)\
**Post date:** [September 29, 2021, 9:13am UTC](https://forum.djangoproject.com/t/update-fields-in-viewsets-and-mixins/9903/1 "2021-09-29T09:13:32Z")

</div>

Hello everyone.  
How do we use update\_fields in Viewsets and Mixins?  
On using partial\_update in UpdateModelMixin.  
model.save() method is trying to run update query on all the model fields instead of updating only changed fields, which is throwing this error →

**message: "update or delete on table “users” violates foreign key constraint “coupons\_user\_code\_fkey” on table “coupons”\nDETAIL: Key (code)=(xyz) is still referenced from table “coupons”.\n"**

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 29, 2021, 11:49am UTC](https://forum.djangoproject.com/t/update-fields-in-viewsets-and-mixins/9903/2 "2021-09-29T11:49:00Z")

</div>

We’re only going to be able to diagnose this in the context of your code. Please post the relevant code and we’ll take a look.

When posting code here in the forum, enclose the code between lines of three backtick - ` characters. You’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code formatted properly, which is critical with Python.
