From 1fe3e2426469d22977a2a17750959b17877b557d Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Wed, 1 Apr 2020 21:20:01 +0200 Subject: [PATCH] Fixed #31411 -- Used RENAME COLUMN on MariaDB 10.5.2+. --- django/db/backends/mysql/schema.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py index d379965c27..db1116d01c 100644 --- a/django/db/backends/mysql/schema.py +++ b/django/db/backends/mysql/schema.py @@ -13,8 +13,6 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): # No 'CASCADE' which works as a no-op in MySQL but is undocumented sql_delete_column = "ALTER TABLE %(table)s DROP COLUMN %(column)s" - sql_rename_column = "ALTER TABLE %(table)s CHANGE %(old_column)s %(new_column)s %(type)s" - sql_delete_unique = "ALTER TABLE %(table)s DROP INDEX %(name)s" sql_create_column_inline_fk = ( ', ADD CONSTRAINT %(name)s FOREIGN KEY (%(column)s) ' @@ -38,6 +36,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): return 'ALTER TABLE %(table)s DROP CONSTRAINT IF EXISTS %(name)s' return 'ALTER TABLE %(table)s DROP CHECK %(name)s' + @property + def sql_rename_column(self): + if self.connection.mysql_is_mariadb and self.connection.mysql_version >= (10, 5, 2): + return super().sql_rename_column + return 'ALTER TABLE %(table)s CHANGE %(old_column)s %(new_column)s %(type)s' + def quote_value(self, value): self.connection.ensure_connection() if isinstance(value, str):