Can not drop index needed in a foreign key constraint?

Can not drop index needed in a foreign key constraint?

By default, it will have the same name as the constraint. When there is only one index that can be used for the foreign key, it can’t be dropped. If you really wan’t to drop it, you either have to drop the foreign key constraint or to create another index for it first.

How do you drop a foreign key constraint?

To delete a foreign key constraint

  1. In Object Explorer, expand the table with the constraint and then expand Keys.
  2. Right-click the constraint and then click Delete.
  3. In the Delete Object dialog box, click OK.

Can not drop foreign key?

the reason why you cannot drop InstructorID is because you need to use the name of the constraint of the Foreign key . KevDev specified that you must run ‘SHOW CREATE TABLE course’ to find the constraint name. after doing so , you can delete the foreign key.

How do I drop a unique key constraint in MySQL?

Drop Unique Constraint The syntax for dropping a unique constraint in MySQL is: ALTER TABLE table_name DROP INDEX constraint_name; table_name. The name of the table to modify.

Can we write a query to drop a foreign key?

ALTER TABLE statement is used to drop a foreign key from a table once it has been created. Syntax: ALTER TABLE table_name.

Can a FOREIGN KEY constraint be dropped in MySQL?

By default, it will have the same name as the constraint. When there is only one index that can be used for the foreign key, it can’t be dropped. If you really wan’t to drop it, you either have to drop the foreign key constraint or to create another index for it first. you have the theory that other answers lacked.

How to remove index from foreign key constraint?

The error code gives us the name of the foreign key and the table where it was defined, so the code is: You can show Relation view in phpMyAdmin and first delete foreign key. After this you can remove index. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.

How to repeat ” cannot drop Index in foreign key “?

How to repeat: 1. Load the above attached dump. 2. Run: ALTER TABLE project_erc20token DROP INDEX unique_token_data; Attachment: dump.sql (application/sql, text ), 19.28 KiB. I mean if it is not a big bug of MySQL, then at least make error message more clear.

When do I try to remove a unique index?

Description: When I try to remove a unique index, MySQL Ver 5.7.26-0ubuntu0.19.04.1 says that it is needed in a foreign key constraint: mysql> ALTER TABLE project_erc20token DROP INDEX unique_token_data; ERROR 1553 (HY000): Cannot drop index ‘unique_token_data’: needed in a foreign key constraint But there is no such foreign key in the DB!