From 25e01d0761abbb78a8b0983e6a1d224767f5a000 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Mon, 14 Oct 2024 19:06:37 +0100 Subject: [PATCH] Default nullable fields to null in unique constraints checks --- rest_framework/serializers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index b1b7b6477..f37bd3a3d 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -1490,6 +1490,8 @@ class ModelSerializer(Serializer): default = timezone.now elif unique_constraint_field.has_default(): default = unique_constraint_field.default + elif unique_constraint_field.null: + default = None else: default = empty