[5.0.x] Fixed #34936 -- Fixed migration crash for DecimalField with db_default on SQLite.

CAST() must be wrapped in parentheses to be recognized as an expression on SQLite.

Regression in 7414704e88.

Backport of 797957fb48 from main
This commit is contained in:
David Sanders 2023-10-30 20:44:44 +11:00 committed by Mariusz Felisiak
parent b735b90f43
commit 8dde0504f3
4 changed files with 15 additions and 4 deletions

View file

@ -27,7 +27,7 @@ class SQLiteNumericMixin:
sql, params = self.as_sql(compiler, connection, **extra_context)
try:
if self.output_field.get_internal_type() == "DecimalField":
sql = "CAST(%s AS NUMERIC)" % sql
sql = "(CAST(%s AS NUMERIC))" % sql
except FieldError:
pass
return sql, params