diff --git a/tests/json_null_tests/__init__.py b/tests/json_null_tests/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/json_null_tests/models.py b/tests/json_null_tests/models.py
new file mode 100644
index 0000000000..c4a30b3047
-
|
+
|
|
| 1 | from django.db import models |
| 2 | |
| 3 | |
| 4 | class JSONFieldModel(models.Model): |
| 5 | data = models.JSONField(null=True, blank=True, default=None) |
| 6 | |
| 7 | class Meta: |
| 8 | required_db_features = {"supports_json_field"} |
| 9 | constraints = [ |
| 10 | models.CheckConstraint( |
| 11 | check=~models.Q(data=models.Value(None, models.JSONField())), |
| 12 | name="json_data_cant_be_json_null", |
| 13 | ), |
| 14 | ] |
diff --git a/tests/json_null_tests/tests.py b/tests/json_null_tests/tests.py
new file mode 100644
index 0000000000..0488040dfa
-
|
+
|
|
| 1 | from django.test import TestCase, skipUnlessDBFeature |
| 2 | |
| 3 | from .models import JSONFieldModel |
| 4 | |
| 5 | |
| 6 | class CheckConstraintTests(TestCase): |
| 7 | @skipUnlessDBFeature("supports_json_field") |
| 8 | def test_full_clean_on_null_value(self): |
| 9 | instance = JSONFieldModel.objects.create(data=None) # data = SQL Null value |
| 10 | instance.full_clean() |