From: Moriyoshi Koizumi Date: Tue, 24 Jul 2012 16:24:14 +0000 (+0900) Subject: Render the default value in the way it correctly reflects the type of the original... X-Git-Tag: rel_0_4_0~16^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74112002c1148473824cea8a6458020e819e1934;p=thirdparty%2Fsqlalchemy%2Falembic.git Render the default value in the way it correctly reflects the type of the original value. This is needed to deal with the case where the coercing isn't supposed to work, as follows: mysql> CREATE TABLE foo (t1 TIMESTAMP DEFAULT '0'); ERROR 1067 (42000): Invalid default value for 't1' --- diff --git a/alembic/ddl/mysql.py b/alembic/ddl/mysql.py index f5afc22d..17920b4f 100644 --- a/alembic/ddl/mysql.py +++ b/alembic/ddl/mysql.py @@ -75,14 +75,20 @@ def _mysql_alter_column(element, compiler, **kw): ), ) +def render_value(compiler, expr): + if isinstance(expr, basestring): + return "'%s'" % expr + else: + return compiler.sql_compiler.process(expr) + def _mysql_colspec(compiler, name, nullable, server_default, type_): spec = "%s %s %s" % ( name, compiler.dialect.type_compiler.process(type_), "NULL" if nullable else "NOT NULL" ) - if server_default: - spec += " DEFAULT '%s'" % server_default + if server_default != False: + spec += " DEFAULT %s" % render_value(compiler, server_default) return spec