Last Updated : 12 Jul, 2025
Field validations in Django help make sure the data you enter into your database is correct and follows certain rules. Django automatically checks the data based on the type of field you use, so you don’t have to write extra code to validate it yourself.
Django provides built-in validations for every field type, making it easier for developers to enforce rules without writing extra code.
How Do Built-in Validations WorkEach type of field in Django has its own built-in checks. For example:
If you try to save wrong data, Django will give an error and won’t let the data be saved.
Demonstration of Built-in ValidationConsider a project named geeksforgeeks having an app named geeks.
Refer to the following articles to check how to create a project and an app in Django.
Enter the following code into models.py file of geeks app.
Python
from django.db import models
class GeeksModel(models.Model):
geeks_field = models.IntegerField()
def __str__(self):
return str(self.geeks_field)
After running makemigrations and migrate on Django and rendering above model, let us try to create an instance using string "GfG is Best".
You can see in the admin interface, one can not enter a string in an IntegerField. Similarly, every field has its own validations.
Django has choices of fields for almost every data you want to store in database such as IntegerField for integer and CharField for strings. But there are some built-in validations which you can apply on these fields too.
For example, unique=True will limit the entries of a particular field to unique entries. Below is a list of built-in validations you can use for your field to make more changes.
Field Options Description Null If True, Django will store empty values as NULL in the database. Default is False. Blank If True, the field is allowed to be blank. Default is False. db_column The name of the database column to use for this field. If this isn’t given, Django will use the field’s name.Read Next: Custom Field Validations in Django Models
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4