Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the reason why mysql is not allowed to delete foreign keys?

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail what is the reason for mysql not to delete foreign keys. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.

1. MYSQL automatically creates an index with the same name after creating a foreign key.

2. When deleting a foreign key, if the index with the same name is not deleted, MYSQL considers that the foreign key still exists--MYSQL will continue to display the foreign key in the show keys command, and when you drop the table,MYSQL will continue to prompt you with "a foreign key constraint fails", that is, the foreign key constraint fails.

3. Naturally, when you try to delete the foreign key you see in show keys again, you get a 1025 error, which is exactly what the web says, the foreign key name is wrong, because the foreign key no longer exists. Unfortunately, you can see that foreign keys are still there, whether you're manipulating them from show keys or other tables, and that's misleading.

Solution:

1. Delete index first

mysql> show index from tableName;mysql> alter table tableName drop index FKxxxxxxxxxxxxxx;

2. Delete foreign key again

mysql> show keys from tableName;mysql> alter table tableName drop foreign key FKxxxxxxxxxxxxxx;

If that doesn't work, try deleting the foreign key before deleting the index, or reconnecting the database.

About mysql do not let delete foreign key reason is what to share here, hope the above content can have some help to everyone, can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report