summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/schema.py
diff options
context:
space:
mode:
authorkimsoungryoul <kimsoungryoul@gmail.com>2022-10-16 14:59:39 +0900
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-28 06:28:07 +0100
commit78f163a4fb3937aca2e71786fbdd51a0ef39629e (patch)
tree7e61c2f8d96b9dab60e317d3483460064327d701 /django/db/backends/mysql/schema.py
parent68ef274bc505cd44f305c03cbf84cf08826200a8 (diff)
downloaddjango-78f163a4fb3937aca2e71786fbdd51a0ef39629e.tar.gz
Fixed #18468 -- Added support for comments on columns and tables.
Thanks Jared Chung, Tom Carrick, David Smith, Nick Pope, and Mariusz Felisiak for reviews. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-authored-by: Nick Pope <nick@nickpope.me.uk>
Diffstat (limited to 'django/db/backends/mysql/schema.py')
-rw-r--r--django/db/backends/mysql/schema.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py
index 6be755f8fb..64771fe6c3 100644
--- a/django/db/backends/mysql/schema.py
+++ b/django/db/backends/mysql/schema.py
@@ -9,7 +9,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
sql_alter_column_null = "MODIFY %(column)s %(type)s NULL"
sql_alter_column_not_null = "MODIFY %(column)s %(type)s NOT NULL"
- sql_alter_column_type = "MODIFY %(column)s %(type)s%(collation)s"
+ sql_alter_column_type = "MODIFY %(column)s %(type)s%(collation)s%(comment)s"
sql_alter_column_no_default_null = "ALTER COLUMN %(column)s SET DEFAULT NULL"
# No 'CASCADE' which works as a no-op in MySQL but is undocumented
@@ -32,6 +32,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
sql_create_index = "CREATE INDEX %(name)s ON %(table)s (%(columns)s)%(extra)s"
+ sql_alter_table_comment = "ALTER TABLE %(table)s COMMENT = %(comment)s"
+ sql_alter_column_comment = None
+
@property
def sql_delete_check(self):
if self.connection.mysql_is_mariadb:
@@ -228,3 +231,11 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
def _rename_field_sql(self, table, old_field, new_field, new_type):
new_type = self._set_field_new_type_null_status(old_field, new_type)
return super()._rename_field_sql(table, old_field, new_field, new_type)
+
+ def _alter_column_comment_sql(self, model, new_field, new_type, new_db_comment):
+ # Comment is alter when altering the column type.
+ return "", []
+
+ def _comment_sql(self, comment):
+ comment_sql = super()._comment_sql(comment)
+ return f" COMMENT {comment_sql}"