summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2025-11-17 13:43:47 +0100
committerGitHub <noreply@github.com>2025-11-17 13:43:47 +0100
commit1ce6e78dd4beed702f15fa0be798dd17a15d4ba8 (patch)
tree0078da5312fb69897bb6327040d51c3450d2fa3b /django/core
parent5c60763561c67924eff1069e1516b60a59d068d5 (diff)
Fixed #24920 -- Added support for DecimalField with no precision.
Thanks Lily for the review.
Diffstat (limited to 'django/core')
-rw-r--r--django/core/management/commands/inspectdb.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index e44edcfe91..06adfe39ed 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -359,21 +359,15 @@ class Command(BaseCommand):
if field_type in {"CharField", "TextField"} and row.collation:
field_params["db_collation"] = row.collation
- if field_type == "DecimalField":
- if row.precision is None or row.scale is None:
- field_notes.append(
- "max_digits and decimal_places have been guessed, as this "
- "database handles decimal fields as float"
- )
- field_params["max_digits"] = (
- row.precision if row.precision is not None else 10
- )
- field_params["decimal_places"] = (
- row.scale if row.scale is not None else 5
- )
- else:
- field_params["max_digits"] = row.precision
- field_params["decimal_places"] = row.scale
+ if field_type == "DecimalField" and (
+ # This can generate DecimalFields with only one of max_digits and
+ # decimal_fields specified. This configuration would be incorrect,
+ # but nothing more correct could be generated.
+ row.precision is not None
+ or row.scale is not None
+ ):
+ field_params["max_digits"] = row.precision
+ field_params["decimal_places"] = row.scale
return field_type, field_params, field_notes