{"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/44fb3450330204b222ff05135e1fbbbdb28c44db/alembic/ddl/mysql.py#L535-L557","documentation":"MySQL has no single generic 'DROP CONSTRAINT' syntax; constraints must be dropped by type (FOREIGN KEY, PRIMARY KEY, UNIQUE, CHECK). The MariaDB/MySQL compiler handles known constraint types explicitly and raises for anything else to avoid emitting invalid SQL.","triggerScenarios":"Calling op.drop_constraint('t', 'name') without specifying a type, or passing a constraint object whose class is not ForeignKeyConstraint, PrimaryKeyConstraint, UniqueConstraint, or CheckConstraint.","commonSituations":"A migration generated against another dialect (PostgreSQL) that uses generic drop_constraint and is then applied to MySQL; dropping a custom constraint subclass; passing type_='check' on MySQL where only the CHECK branch is valid for MariaDB/MySQL 8+.","solutions":["Specify the constraint type: op.drop_constraint('t', 'name', type_='foreignkey') (or 'primary', 'unique', 'check').","Use batch_alter_table, which reflects the constraint type and emits the correct MySQL DDL.","For check constraints, ensure you are on MySQL 8.0+ / MariaDB which support DROP CHECK / DROP CONSTRAINT."],"exampleFix":"// before\nop.drop_constraint('orders', 'fk_orders_user')  # MySQL -> NotImplementedError\n// after\nop.drop_constraint('orders', 'fk_orders_user', type_='foreignkey')","handlingStrategy":"validation","validationCode":"if dialect_name in (\"mysql\", \"mariadb\"):\n    assert constraint_type in (\"foreignkey\", \"primary\", \"unique\", \"check\"), \"Specify constraint type for MySQL drop_constraint\"","typeGuard":"def is_known_mysql_constraint(type_) -> bool:\n    return type_ in (\"foreignkey\", \"primary\", \"unique\", \"check\")","tryCatchPattern":null,"preventionTips":["Always pass type_= to op.drop_constraint on MySQL.","Prefer batch_alter_table.drop_constraint which reflects the type.","Test constraint drops against MySQL specifically."],"tags":["mysql","mariadb","constraints","drop-constraint"],"analyzedSha":"44fb3450330204b222ff05135e1fbbbdb28c44db","analyzedAt":"2026-08-04T19:57:10.248Z","schemaVersion":2}