Skip to content

Commit a63ee45

Browse files
committed
Fix Decimal database defaults
1 parent 9cd5fa9 commit a63ee45

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

django_snowflake/features.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class DatabaseFeatures(BaseDatabaseFeatures):
2929
has_json_object_function = False
3030
indexes_foreign_keys = False
3131
nulls_order_largest = True
32+
# At least for DecimalField, Snowflake errors with "Default value data type
33+
# does not match data type for column" if the default isn't serialized.
34+
requires_literal_defaults = True
3235
supported_explain_formats = {'JSON', 'TABULAR', 'TEXT'}
3336
supports_comments = True
3437
supports_comments_inline = True

django_snowflake/schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,13 @@ def _column_generated_sql(self, field):
169169

170170
def quote_value(self, value):
171171
if isinstance(value, str):
172-
return "'%s'" % value.replace("'", "\\'")
172+
return "'%s'" % value.replace("'", "\\'").replace("%", "%%")
173173
else:
174174
return str(value)
175175

176+
def prepare_default(self, value):
177+
return self.quote_value(value)
178+
176179
def skip_default_on_alter(self, field):
177180
# Snowflake: Unsupported feature 'Alter Column Set Default'.
178181
return True

0 commit comments

Comments
 (0)