):
return compiler.visit_drop_constraint(element, **kw)
elif isinstance(constraint, schema.CheckConstraint):
- raise NotImplementedError(
- "MySQL does not support CHECK constraints.")
+ # note that SQLAlchemy as of 1.2 does not yet support
+ # DROP CONSTRAINT for MySQL/MariaDB, so we implement fully
+ # here.
+ return "ALTER TABLE %s DROP CONSTRAINT %s" % \
+ (compiler.preparer.format_table(constraint.table), constraint.name)
else:
raise NotImplementedError(
"No generic 'DROP CONSTRAINT' in MySQL - "
--- /dev/null
+.. change::
+ :tags: bug, mysql
+ :tickets: 479
+
+ Added support for DROP CONSTRAINT to the MySQL Alembic
+ dialect to support MariaDB 10.2 which now has real
+ CHECK constraints. Note this change does **not**
+ add autogenerate support, only support for op.drop_constraint()
+ to work.
)
def test_drop_check(self):
- op_fixture('mysql')
- assert_raises_message(
- NotImplementedError,
- "MySQL does not support CHECK constraints.",
- op.drop_constraint, "f1", "t1", "check"
+ context = op_fixture('mysql')
+ op.drop_constraint("f1", "t1", "check")
+ context.assert_(
+ "ALTER TABLE t1 DROP CONSTRAINT f1"
)
def test_drop_unknown(self):