Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant' change mysql schematype due to DROP constraint #355

Closed
sqlalchemy-bot opened this issue Jan 22, 2016 · 4 comments
Closed

cant' change mysql schematype due to DROP constraint #355

sqlalchemy-bot opened this issue Jan 22, 2016 · 4 comments
Labels
Milestone

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Michael Bayer (@zzzeek)

diff --git a/tests/test_mysql.py b/tests/test_mysql.py
index 2dc8838..7600ebf 100644
--- a/tests/test_mysql.py
+++ b/tests/test_mysql.py
@@ -1,4 +1,4 @@
-from sqlalchemy import Integer, func
+from sqlalchemy import Integer, func, Boolean
 from alembic.testing.fixtures import TestBase
 from alembic.testing import config
 from sqlalchemy import TIMESTAMP, MetaData, Table, Column, text
@@ -102,6 +102,17 @@ class MySQLOpTest(TestBase):
             'ALTER TABLE t ALTER COLUMN c DROP DEFAULT'
         )
 
+    def test_alter_column_remove_schematype(self):
+        context = op_fixture('mysql')
+        op.alter_column(
+            "t", "c",
+            type_=Integer,
+            existing_type=Boolean(create_constraint=True, name="ck1"),
+            server_default=None)
+        context.assert_(
+            'ALTER TABLE t MODIFY c INTEGER NULL'
+        )
+
     def test_alter_column_modify_default(self):
         context = op_fixture('mysql')
         # notice we dont need the existing type on this one...

stack:

#!


Traceback (most recent call last):
  File "/home/classic/dev/alembic/tests/test_mysql.py", line 111, in test_alter_column_remove_schematype
    server_default=None)
  File "<string>", line 8, in alter_column
  File "<string>", line 3, in alter_column
  File "/home/classic/dev/alembic/alembic/operations/ops.py", line 1414, in alter_column
    return operations.invoke(alt)
  File "/home/classic/dev/alembic/alembic/operations/base.py", line 318, in invoke
    return fn(self, operation)
  File "/home/classic/dev/alembic/alembic/operations/toimpl.py", line 41, in alter_column
    operations.impl.drop_constraint(constraint)
  File "/home/classic/dev/alembic/alembic/ddl/impl.py", line 183, in drop_constraint
    self._exec(schema.DropConstraint(const))
  File "/home/classic/dev/alembic/alembic/ddl/impl.py", line 118, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/home/classic/dev/alembic/alembic/testing/fixtures.py", line 151, in execute
    sql = text_type(stmt.compile(dialect=ctx_dialect))
  File "<string>", line 1, in <lambda>
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/sql/elements.py", line 433, in compile
    return self._compiler(dialect, bind=bind, **kw)
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/sql/ddl.py", line 26, in _compiler
    return dialect.ddl_compiler(dialect, self, **kw)
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/sql/compiler.py", line 206, in __init__
    self.string = self.process(self.statement, **compile_kwargs)
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/sql/compiler.py", line 229, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/ext/compiler.py", line 423, in <lambda>
    lambda *arg, **kw: existing(*arg, **kw))
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/ext/compiler.py", line 461, in __call__
    return fn(element, compiler, **kw)
  File "/home/classic/dev/alembic/alembic/ddl/mysql.py", line 312, in _mysql_drop_constraint
    "MySQL does not support CHECK constraints.")
NotImplementedError: MySQL does not support CHECK constraints.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

  • Repaired batch migration support for "schema" types which generate
    constraints, in particular the Boolean datatype which generates
    a CHECK constraint. Previously, an alter column operation with this
    type would fail to correctly accommodate for the CHECK constraint
    on change both from and to this type. In the former case the operation
    would fail entirely, in the latter, the CHECK constraint would
    not get generated. Both of these issues are repaired.
    fixes cant change type of boolean w/ batch #354
  • Changing a schema type such as Boolean to a non-schema type would
    emit a drop constraint operation which emits NotImplementedError for
    the MySQL dialect. This drop constraint operation is now skipped when
    the constraint originates from a schema type.
    fixes cant' change mysql schematype due to DROP constraint #355

9eb7f32

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot
Copy link
Author

Martin Domke (@mdomke) wrote:

Is there any time schedule when this fix does make it into a release?

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

it's released.

@sqlalchemy-bot sqlalchemy-bot added op directives bug Something isn't working labels Nov 27, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the tier 1 milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants