]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Render the default value in the way it correctly reflects the type of the original...
authorMoriyoshi Koizumi <mozo@mozo.jp>
Tue, 24 Jul 2012 16:24:14 +0000 (01:24 +0900)
committerMoriyoshi Koizumi <mozo@mozo.jp>
Tue, 24 Jul 2012 16:24:14 +0000 (01:24 +0900)
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'

alembic/ddl/mysql.py

index f5afc22d75d648bdbfaddd10b5972387732fd223..17920b4f6fae4ed55f216b132ed68fa2a7922004 100644 (file)
@@ -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