Skip to content

Commit 965573a

Browse files
committed
Update get_table_list and add version condition to db_comment
1 parent 69d3024 commit 965573a

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

mssql/introspection.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ def get_table_list(self, cursor):
8282
TABLE_TYPE,
8383
CAST(ep.value AS VARCHAR) AS COMMENT
8484
FROM INFORMATION_SCHEMA.TABLES i
85-
INNER JOIN sys.tables t ON t.name = i.TABLE_NAME
85+
LEFT JOIN sys.tables t ON t.name = i.TABLE_NAME
8686
LEFT JOIN sys.extended_properties ep ON t.object_id = ep.major_id
87-
WHERE
88-
((ep.name = 'MS_DESCRIPTION' AND ep.minor_id >= 0) OR ep.value IS NULL)
89-
AND
90-
i.TABLE_SCHEMA = %s""" % (
87+
AND ((ep.name = 'MS_DESCRIPTION' AND ep.minor_id = 0) OR ep.value IS NULL)
88+
AND i.TABLE_SCHEMA = %s""" % (
9189
get_schema_name())
9290
cursor.execute(sql)
9391
types = {'BASE TABLE': 't', 'VIEW': 'v'}

mssql/schema.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ def _alter_column_null_sql(self, model, old_field, new_field):
197197
if django_version >= (4, 2):
198198
def _alter_column_type_sql(self, model, old_field, new_field, new_type, old_collation, new_collation):
199199
new_type = self._set_field_new_type_null_status(old_field, new_type)
200-
# Check if existing
201-
# Drop exisiting
202200
return super()._alter_column_type_sql(model, old_field, new_field, new_type, old_collation, new_collation)
203201
else:
204202
def _alter_column_type_sql(self, model, old_field, new_field, new_type):
@@ -965,17 +963,18 @@ def add_field(self, model, field):
965963
}
966964
self.execute(sql, params)
967965
# Add field comment, if required.
968-
if (
969-
field.db_comment
970-
and self.connection.features.supports_comments
971-
and not self.connection.features.supports_comments_inline
972-
):
973-
field_type = db_params["type"]
974-
self.execute(
975-
*self._alter_column_comment_sql(
976-
model, field, field_type, field.db_comment
966+
if django_version >= (4, 2):
967+
if (
968+
field.db_comment
969+
and self.connection.features.supports_comments
970+
and not self.connection.features.supports_comments_inline
971+
):
972+
field_type = db_params["type"]
973+
self.execute(
974+
*self._alter_column_comment_sql(
975+
model, field, field_type, field.db_comment
976+
)
977977
)
978-
)
979978
# Add an index, if required
980979
self.deferred_sql.extend(self._field_indexes_sql(model, field))
981980
# Add any FK constraints later

0 commit comments

Comments
 (0)