From 9cab261427731a49ff4a1bf32941fd46eead4724 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 9 Apr 2020 11:16:28 +0200 Subject: [PATCH] Refs #31411 -- Used RENAME COLUMN on MySQL 8.0.4+. MySQL 8.0.3 added support for this syntax but also imposed a restriction against ALTER TABLE RENAME on tables in a foreign key relationship if a LOCK TABLES was active which has been lifted in MySQL 8.0.4+. --- django/db/backends/mysql/schema.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py index db1116d01c..71b021f7c5 100644 --- a/django/db/backends/mysql/schema.py +++ b/django/db/backends/mysql/schema.py @@ -38,7 +38,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): @property def sql_rename_column(self): - if self.connection.mysql_is_mariadb and self.connection.mysql_version >= (10, 5, 2): + # MariaDB >= 10.5.2 and MySQL >= 8.0.4 support an + # "ALTER TABLE ... RENAME COLUMN" statement. + if self.connection.mysql_is_mariadb: + if self.connection.mysql_version >= (10, 5, 2): + return super().sql_rename_column + elif self.connection.mysql_version >= (8, 0, 4): return super().sql_rename_column return 'ALTER TABLE %(table)s CHANGE %(old_column)s %(new_column)s %(type)s'