shaare.it

TypeError: got None for ManyToMany add()

7 Dec 2025

1 min read

TypeError: ManyToMany add None

$ python - <<'PY'
l = []
l.append(None)
PY
# Django ManyToMany.add(None) raises TypeError

Why this happens

You called add() with None or unsaved objects.

Fix

Ensure instances are saved and non-null.

Wrong code

item.tags.add(None)

Fixed code

tag = Tag.objects.create(name='x')
item.tags.add(tag)