Mysql Delete foreign key problem summary _mysql

Source: Internet
Author: User
Tags mysql delete

Mysql:mysql cannot delete the foreign key, rename error on the./ruler/test2child to./ruler/#sql2 -298-92 (errno:152)

It used to be a bug in MySQL, but now it's just an unfriendly place in MySQL.

Examples are as follows:

mysql> ALTER TABLE ruler.test2child DROP FOREIGN KEY test;
ERROR 1025:error on Rename of './ruler/test2child './ruler/#sql2 -298-8f ' (errno:
152)

It is not possible to delete the foreign key, but to use the wrong foreign key name, but the MySQL newspaper's error is outrageous.
The correct error message is to be known by the following query:

Mysql> show InnoDB status; 
------------------------
LATEST FOREIGN KEY error
------------------------
071222 20:48:26 Error in Dropping of a FOREIGN key constraint of table
"ruler".  Test2child ", in
SQL command
ALTER TABLE ruler.test2child DROP FOREIGN KEY Test
cannot find a constraint with The given ID "test".

In addition, other foreign key operations have similar conditions:

such as foreign key new error:

Can ' t create table ' ruler #sql -298_92 ' (errno:150) show
innodb status; 
------------------------
LATEST FOREIGN KEY error
------------------------
071222 20:18:57 Error in  FOREIGN KEY constraint of table ruler/#sql -298_8d:
 foreign Key (Test2code) REFERENCES ruler.test2 (test) on delete set Null:
have defined a SET NULL condition though some of the columns are as not
null.

The test database version is:

5.2.0-falcon-alpha-community-nt

To delete a foreign key:

First delete the foreign key name, then delete the Foreign key field (provided by the MySQL official)

Cases:

ALTER TABLE task drop foreign key fk_reference_7;
ALTER TABLE Task drop column ' assigned ';

The above is a small set to introduce the MySQL delete foreign key issues summary, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.