From: huuyafwww Date: Fri, 4 Oct 2024 17:39:02 +0000 (+0900) Subject: fix: Fixed a bug that caused a syntax error when a function was specified to server_d... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd47fb5373076223352e6c2d40941d86988ac455;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix: Fixed a bug that caused a syntax error when a function was specified to server_default when creating a column in MySQL. --- diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index aa99bf4d68..b841a20445 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1853,6 +1853,11 @@ class MySQLDDLCompiler(compiler.DDLCompiler): colspec.append("DEFAULT " + default) return " ".join(colspec) + def get_column_default_string(self, column): + if hasattr(column.server_default, 'arg') and isinstance(column.server_default.arg, functions.FunctionElement): + return f'({column.server_default.arg})' + return super().get_column_default_string(column) + def post_create_table(self, table): """Build table-level CREATE options like ENGINE and COLLATE."""