From: J. Nick Koston Date: Fri, 24 Mar 2023 21:54:02 +0000 (-1000) Subject: Fix creating zero length char with MySQL X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30123bfe5b942413a1235d5fdd67ec4c4e7833ed;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix creating zero length char with MySQL https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html > MySQL permits you to create a column of type CHAR(0). This is useful primarily when you must be compliant with old applications that depend on the existence of a column but that do not actually use its value. CHAR(0) is also quite nice when you need a column that can take only two values: A column that is defined as CHAR(0) NULL occupies only one bit and can take only the values NULL and (the empty string). --- diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index ebef48a772..46917cfff3 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -2275,7 +2275,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler): ) def visit_CHAR(self, type_, **kw): - if type_.length: + if type_.length is not None: return self._extend_string( type_, {}, "CHAR(%(length)s)" % {"length": type_.length} )