diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 16a07002bc..dd88471d78 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1379,9 +1379,9 @@ class DecimalField(Field): def deconstruct(self): name, path, args, kwargs = super(DecimalField, self).deconstruct() - if self.max_digits: + if self.max_digits is not None: kwargs['max_digits'] = self.max_digits - if self.decimal_places: + if self.decimal_places is not None: kwargs['decimal_places'] = self.decimal_places return name, path, args, kwargs diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py index f7afec536a..8b5bbdf0c9 100644 --- a/tests/field_deconstruction/tests.py +++ b/tests/field_deconstruction/tests.py @@ -110,6 +110,16 @@ class FieldDeconstructionTests(TestCase): self.assertEqual(args, []) self.assertEqual(kwargs, {"max_digits": 5, "decimal_places": 2}) + def test_decimal_field_0_decimal_places(self): + """ + A DecimalField with decimal_places=0 shoudl work (#22272). + """ + field = models.DecimalField(max_digits=5, decimal_places=0) + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, "django.db.models.DecimalField") + self.assertEqual(args, []) + self.assertEqual(kwargs, {"max_digits": 5, "decimal_places": 0}) + def test_email_field(self): field = models.EmailField() name, path, args, kwargs = field.deconstruct()