Open In App

Field Validations and Built-In Fields - Django Models

Last Updated : 10 Oct, 2025
Suggest changes
Share
Like Article
Like
Report

Field validations in Django ensure that the data entered into the database is correct and follows specific rules. Django automatically checks the data based on the type of field used, so no extra validation code is required. Each type of field in Django has its own built-in checks:

  • IntegerField only accepts whole numbers.
  • CharField is for text and limits how long the text can be.
  • DateField checks that the value is a valid date.

If invalid data is entered, Django raises an error and prevents saving.

Example: Consider a project named 'geeksforgeeks' having an app named 'geeks'.

In geeks/models.py:  

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, Django creates the corresponding database table with an integer column.

If you try to create an instance using a string value like 'GfG is Best' for geeks_field, Django’s validation system will raise an error, as only integers are allowed.

built-in-validation-django-models

You can verify it through Django admin interface, you’ll notice that non-numeric input is automatically rejected - demonstrating how each field enforces its own built-in validation.

Extra Built-in Validations

Django provides fields for almost every type of data, such as IntegerField for numbers and CharField for text. In addition, there are built-in validations that can be applied to these fields to enforce extra rules. Some of the most used validations are listed below:

Field OptionsDescription
NullIf True, Django will store empty values as NULL in the database. Default is False.
BlankIf True, the field is allowed to be blank. Default is False.
db_columnThe name of the database column to use for this field. If this isn’t given, Django will use the field’s name. 
 
DefaultThe default value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created. 
 
help_textExtra “help” text to be displayed with the form widget. It’s useful for documentation even if your field isn’t used on a form. 
 
primary_keyIf True, this field is the primary key for the model.
editableIf False, the field will not be displayed in the admin or any other ModelForm. They are also skipped during model validation. Default is True
 
error_messagesThe error_messages argument lets you override the default messages that the field will raise. Pass in a dictionary with keys matching the error messages you want to override. 
 
help_textExtra “help” text to be displayed with the form widget. It’s useful for documentation even if your field isn’t used on a form. 
 
verbose_nameA human-readable name for the field. If the verbose name isn’t given, Django will automatically create it using the field’s attribute name, converting underscores to spaces. 
 
validatorsA list of validators to run for this field. See the validators documentation for more information. 
 
UniqueIf True, this field must be unique throughout the table. 
 

Read Next: Custom Field Validations in Django Models


Explore