Repository: django/django
File: django/db/models/fields/__init__.py (Python)

Code before:
        errors = super().check(**kwargs)

        digits_errors = [
            *self._check_decimal_places(),
            *self._check_max_digits(),
        ]
        if not digits_errors:
            errors.extend(self._check_decimal_places_and_max_digits(**kwargs))
        else:
            errors.extend(digits_errors)
        return errors

    def _check_decimal_places(self):
        try:
            decimal_places = int(self.decimal_places)
            if decimal_places < 0:
                raise ValueError()
        except TypeError:
            return [
                checks.Error(
                    "DecimalFields must define a 'decimal_places' attribute.",
                    obj=self,
                    id="fields.E130",
                )
            ]
        except ValueError:
            return [
                checks.Error(
                    "'decimal_places' must be a non-negative integer.",
                    obj=self,
                    id="fields.E131",
                )
            ]
        else:
            return []

    def _check_max_digits(self):
        try:
            max_digits = int(self.max_digits)
            if max_digits <= 0:
                raise ValueError()
        except TypeError:
            return [
                checks.Error(
                    "DecimalFields must define a 'max_digits' attribute.",
                    obj=self,
                    id="fields.E132",
                )
            ]
        except ValueError:
            return [

Review comment (suggestion):
I believe this should be a database dependent check similar to `_check_db_collation()`, not only examining the default database.

Code after:
        errors = super().check(**kwargs)

        digits_errors = [
            *self._check_decimal_places(),
            *self._check_max_digits(),
        ]
        if not digits_errors:
            errors.extend(self._check_decimal_places_and_max_digits(**kwargs))
        else:
            errors.extend(digits_errors)
        return errors

    def _check_decimal_places(self):
        if self.decimal_places is None:
            if (
                not connection.features.supports_no_precision_decimalfield
                and "supports_no_precision_decimalfield"
                not in self.model._meta.required_db_features
            ):
                return [
                    checks.Error(
                        "DecimalFields must define a 'decimal_places' attribute.",
                        obj=self,
                        id="fields.E130",
                    )
                ]
            elif self.max_digits is not None:
                return [
                    checks.Error(
                        "DecimalField’s max_digits and decimal_places must both "
                        "be defined or both omitted.",
                        obj=self,
                        id="fields.E135",
                    ),
                ]
        else:
            try:
                decimal_places = int(self.decimal_places)
                if decimal_places < 0:
                    raise ValueError()
            except ValueError:
                return [
                    checks.Error(
                        "'decimal_places' must be a non-negative integer.",
                        obj=self,
                        id="fields.E131",
                    )
                ]
        return []

    def _check_max_digits(self):