shaare.it

ValueError: cannot set NULL on non-null field

7 Dec 2025

1 min read

ValueError: cannot set NULL on non-null field

$ python manage.py shell -c "from app.models import Item; i=Item(); i.name=None; i.save()"
Traceback (most recent call last):
  ...
IntegrityError: null value in column "name" violates not-null constraint

Why this happens

Field doesn’t allow NULL.

Fix

Provide value or change field to null=True, blank=True.

Wrong code

i.name = None

Fixed code

i.name = "Name"
# or adjust model field