diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2025-11-17 13:43:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-17 13:43:47 +0100 |
| commit | 1ce6e78dd4beed702f15fa0be798dd17a15d4ba8 (patch) | |
| tree | 0078da5312fb69897bb6327040d51c3450d2fa3b /django/db/backends/postgresql/base.py | |
| parent | 5c60763561c67924eff1069e1516b60a59d068d5 (diff) | |
Fixed #24920 -- Added support for DecimalField with no precision.
Thanks Lily for the review.
Diffstat (limited to 'django/db/backends/postgresql/base.py')
| -rw-r--r-- | django/db/backends/postgresql/base.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index e2728afea5..42b37ab3c2 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -89,6 +89,12 @@ def _get_varchar_column(data): return "varchar(%(max_length)s)" % data +def _get_decimal_column(data): + if data["max_digits"] is None and data["decimal_places"] is None: + return "numeric" + return "numeric(%(max_digits)s, %(decimal_places)s)" % data + + class DatabaseWrapper(BaseDatabaseWrapper): vendor = "postgresql" display_name = "PostgreSQL" @@ -105,7 +111,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): "CharField": _get_varchar_column, "DateField": "date", "DateTimeField": "timestamp with time zone", - "DecimalField": "numeric(%(max_digits)s, %(decimal_places)s)", + "DecimalField": _get_decimal_column, "DurationField": "interval", "FileField": "varchar(%(max_length)s)", "FilePathField": "varchar(%(max_length)s)", |
