{"record":{"id":"b6c122b9676d034e","repo":"sqlalchemy/alembic","slug":"no-generic-drop-constraint-in-mysql-please-spe","errorCode":null,"errorMessage":"No generic 'DROP CONSTRAINT' in MySQL - please specify constraint type","messagePattern":"No generic 'DROP CONSTRAINT' in MySQL - please specify constraint type","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"alembic/ddl/mysql.py","lineNumber":553,"sourceCode":"    ):\n        assert not kw\n        return compiler.visit_drop_constraint(element)\n    elif isinstance(constraint, schema.CheckConstraint):\n        # note that SQLAlchemy as of 1.2 does not yet support\n        # DROP CONSTRAINT for MySQL/MariaDB, so we implement fully\n        # here.\n        if compiler.dialect.is_mariadb:\n            return \"ALTER TABLE %s DROP CONSTRAINT %s\" % (\n                compiler.preparer.format_table(constraint.table),\n                compiler.preparer.format_constraint(constraint),\n            )\n        else:\n            return \"ALTER TABLE %s DROP CHECK %s\" % (\n                compiler.preparer.format_table(constraint.table),\n                compiler.preparer.format_constraint(constraint),\n            )\n    else:\n        raise NotImplementedError(\n            \"No generic 'DROP CONSTRAINT' in MySQL - \"\n            \"please specify constraint type\"\n        )\n","sourceCodeStart":535,"sourceCodeEnd":557,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/5551b5d35f985c99cb8f1af2b3c526b050e4c059/alembic/ddl/mysql.py#L535-L557","documentation":"MySQL/MariaDB DropConstraint compilation raises NotImplementedError when the constraint being dropped is not a ForeignKeyConstraint, PrimaryKeyConstraint, UniqueConstraint, or CheckConstraint. MySQL has no generic DROP CONSTRAINT syntax; each constraint type has its own DROP FOREIGN KEY / DROP PRIMARY KEY / DROP INDEX / DROP CHECK statement, so Alembic needs a typed constraint.","triggerScenarios":"Calling op.drop_constraint() with a generic/anonymous Constraint object, or a custom Constraint subclass not recognized by the MySQL dispatch; dropping a constraint whose type is ambiguous.","commonSituations":"Custom constraint classes; code that constructs schema.DropConstraint with a bare Constraint(name=...) lacking a concrete subclass; migrating from another dialect where generic DROP CONSTRAINT worked.","solutions":["Drop a typed constraint: use op.drop_constraint with a ForeignKeyConstraint, PrimaryKeyConstraint, UniqueConstraint, or CheckConstraint.","For foreign keys, use 'foreignkey' type via op.drop_constraint('name', 't', type_='foreignkey').","For check constraints on MariaDB/MySQL, ensure the constraint is a CheckConstraint so DROP CHECK / DROP CONSTRAINT is emitted."],"exampleFix":"# before (ambiguous)\nop.drop_constraint('my_constraint', 'my_table')\n\n# after (specify type)\nop.drop_constraint('my_fk', 'my_table', type_='foreignkey')","handlingStrategy":"validation","validationCode":"VALID_TYPES = {'foreignkey', 'primary', 'unique', 'check'}\n\ndef safe_drop_constraint(op, name, table, type_=None):\n    if type_ not in VALID_TYPES:\n        raise ValueError(f'specify type_ in {VALID_TYPES}')\n    op.drop_constraint(name, table, type_=type_)","typeGuard":"def is_known_constraint_type(t: str | None) -> bool:\n    return t in {'foreignkey', 'primary', 'unique', 'check'}","tryCatchPattern":null,"preventionTips":["Always pass the type_ argument to op.drop_constraint on MySQL/MariaDB.","Avoid constructing generic schema.DropConstraint with a bare Constraint subclass.","Test constraint drops against the target dialect in CI."],"tags":["mysql","mariadb","drop-constraint","ddl","dialect"],"backgroundTag":null,"analyzedSha":"5551b5d35f985c99cb8f1af2b3c526b050e4c059","analyzedAt":"2026-08-11T01:38:46.612Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}