Skip to content

Commit 37f7dd9

Browse files
authored
FEAT:Support 5.1-Removed Deprecated Fields (#454)
* removed deprecated fields * modified comment
1 parent 30e7496 commit 37f7dd9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

mssql/functions.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,16 @@ def _get_check_sql(self, model, schema_editor):
377377
query = Query(model=model, alias_cols=False)
378378
else:
379379
query = Query(model=model)
380-
where = query.build_where(self.check)
380+
# Build the query to check the condition of the CheckConstraint.
381+
# Note: Starting from Django 5.1, the CheckConstraint API changed:
382+
# the attribute 'self.check' was replaced by 'self.condition'.
383+
# For backwards compatibility, we use 'self.check' for versions < 5.1,
384+
# and 'self.condition' for 5.1 and above.
385+
if VERSION >= (5, 1):
386+
where = query.build_where(self.condition)
387+
else:
388+
# use check for backwards compatibility
389+
where = query.build_where(self.check)
381390
compiler = query.get_compiler(connection=schema_editor.connection)
382391
sql, params = where.as_sql(compiler, schema_editor.connection)
383392
if schema_editor.connection.vendor == 'microsoft':

0 commit comments

Comments
 (0)