Improved ValueError msg

This commit is contained in:
Genaro Camele 2025-10-13 16:29:24 -03:00 committed by GitHub
parent 04703dca8a
commit 9d8b176374
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1094,8 +1094,7 @@ class ModelSerializer(Serializer):
for field_name in declared_fields.keys(): for field_name in declared_fields.keys():
if field_name in info.relations and info.relations[field_name].to_many and declared_fields[field_name].default is None: if field_name in info.relations and info.relations[field_name].to_many and declared_fields[field_name].default is None:
raise ValueError( raise ValueError(
f"The field '{field_name}' on serializer '{self.__class__.__name__}' is a ManyToMany field and cannot have a default value of None. " f"The field '{field_name}' on serializer '{self.__class__.__name__}' is a ManyToMany field and cannot have a default value of None."
"Please set an appropriate default value, such as an empty list, or remove the default."
) )
for field_name in field_names: for field_name in field_names: