Skip to content

QueryInterface removeConstraint method fails to remove CHECK constraints (MySQL) #17382

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

Open
3 of 6 tasks
fullmetalsheep opened this issue Jun 17, 2024 · 1 comment
Open
3 of 6 tasks
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet

Comments

@fullmetalsheep
Copy link

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Bug Description

Context: I'm using sequelize migrations to drop an existing CHECK constraint on one of our tables. The dialect is MySQL Community Server 8.1

When removeConstraint is invoked with correct schema and constraint name, it returns this error: Error Code: 1091. Can't DROP 'constraint_to_delete'; check that column/key exists. I have verified that this constraint definitely exists.

I debugged removeConstraint function further with logging and found out that internally it runs these SQL commands:

SELECT CONSTRAINT_CATALOG AS constraintCatalog, CONSTRAINT_NAME AS constraintName, CONSTRAINT_SCHEMA AS constraintSchema, CONSTRAINT_TYPE AS constraintType, 
TABLE_NAME AS tableName, TABLE_SCHEMA AS tableSchema from INFORMATION_SCHEMA.TABLE_CONSTRAINTS 

WHERE table_name='mytable' AND constraint_name = 'constraint_to_delete' AND TABLE_SCHEMA = 'mydatabase';

DROP INDEX constraint_to_delete on mytable;

Note that it tries to use DROP INDEX to drop the constraint. At least in MySQL DROP INDEX doesnt seem to work for dropping constraints.

If I run this SQL query ALTER TABLE mytable DROP CONSTRAINT constraint_to_delete It gets removed as expected.

Reproducible Example

Here is the link to the SSCCE for this issue: n/a

What do you expect to happen?

The CHECK constraint should be dropped.

What is actually happening?

removeConstraint throws this error: Error Code: 1091. Can't DROP 'constraint_to_delete'; check that column/key exists despite the CHECK constraint definitely existing.

Environment

  • Sequelize version: 6.32.0
  • Node.js version: v22.1.0
  • If TypeScript related: TypeScript version: 4.9.4
  • Database & Version: MySQL Community Server 8.1
  • Connector library & Version: mysql2 2.3.3

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

@fullmetalsheep fullmetalsheep added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug DEPRECATED: replace with the "bug" issue type labels Jun 17, 2024
@WikiRik
Copy link
Member

WikiRik commented Jun 17, 2024

I believe we've done some work on this in the v7 alphas. Can you check with installing @sequelize/core@alpha?

@WikiRik WikiRik moved this to Check if fixed in v7 in Starting issues Feb 12, 2025
@ephys ephys removed the type: bug DEPRECATED: replace with the "bug" issue type label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet
Projects
Status: Check if fixed in v7
Development

No branches or pull requests

3 participants