Commits

dairiki committed 6b13e35

Bug: exception on alter_column(..., server_default=None) in mysql

Comments (0)

Files changed (4)

alembic/ddl/mssql.py

         )
 
         if server_default is not False:
-            if existing_server_default is not False or \
-                server_default is None:
+            # b/c: treat existing_server_default=False as None since
+            # that was what was accepted (contrary to the docs) in
+            # alembic<=0.6.3
+            have_existing_default = (
+                existing_server_default is not None
+                and existing_server_default is not False)
+            if have_existing_default or server_default is None:
                 self._exec(
                     _exec_drop_col_constraint(self,
                             table_name, column_name,

alembic/ddl/mysql.py

     )
     if autoincrement:
         spec += " AUTO_INCREMENT"
-    if server_default != False:
+    # b/c: treat server_default=False as None since that was
+    # what was accepted (contrary to the docs) in alembic<=0.6.3
+    if server_default is not None and server_default is not False:
         spec += " DEFAULT %s" % _render_value(compiler, server_default)
 
     return spec

alembic/operations.py

                         type_=None,
                         autoincrement=None,
                         existing_type=None,
-                        existing_server_default=False,
+                        existing_server_default=None,
                         existing_nullable=None,
                         existing_autoincrement=None,
                         schema=None

tests/test_mysql.py

             'ALTER TABLE t1 CHANGE c1 c2 INTEGER NULL'
         )
 
+    def test_col_remove_server_default(self):
+        context = op_fixture('mysql')
+        op.alter_column('t1', 'c1', new_column_name="c2", existing_type=Integer,
+                                    existing_server_default='1',
+                                    server_default=None)
+        context.assert_(
+            'ALTER TABLE t1 CHANGE c1 c2 INTEGER NULL'
+        )
+
     def test_col_nullable(self):
         context = op_fixture('mysql')
         op.alter_column('t1', 'c1', nullable=False, existing_type=Integer)