# What is the correct way to validate the data in a model instance?

**URL:** <https://forum.djangoproject.com/t/what-is-the-correct-way-to-validate-the-data-in-a-model-instance/28710>\
**Category:** Using the ORM\
**Created:** [March 4, 2024, 11:47pm UTC](https://forum.djangoproject.com/t/what-is-the-correct-way-to-validate-the-data-in-a-model-instance/28710 "2024-03-04T23:47:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ermantraun](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ermantraun/32/19395_2.png) [@ermantraun](https://forum.djangoproject.com/u/ermantraun)\
**Post date:** [March 4, 2024, 11:47pm UTC](https://forum.djangoproject.com/t/what-is-the-correct-way-to-validate-the-data-in-a-model-instance/28710/1 "2024-03-04T23:47:57Z")

</div>

Which is preferable to use: checking values for a field in the database at the application level, for example: `def save(self, force\_insert=False, force\_update=False, use=None, update\_fields=None):

```
    `if update_fields is not None:
        self.full_clean(exclude=update_fields)
    else:
        self.full_clean()
      
    super().save(force_insert=force_insert, force_update=force_update, 
                     using=using, update_fields=update_fields,)`.

```

Or is the validation at the database level?

---

<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:** [March 5, 2024, 1:49am UTC](https://forum.djangoproject.com/t/what-is-the-correct-way-to-validate-the-data-in-a-model-instance/28710/2 "2024-03-05T01:49:25Z")

</div>

It depends upon what needs to be validated.

If you’ve got fields that are restricted to values based upon some business logic, and you don’t have a suitable set of constraints in the database, then you _need_ to perform the validation in Django.

Otherwise, it’s an architectural decision based on other considerations. There’s no “best” or “right” answer for every circumstance. There are always tradeoffs.
