MySQL foreign key deletion problem summary, mysql deletion Summary

Source: Internet
Author: User

MySQL foreign key deletion problem summary, mysql deletion Summary

MySQL: MySQL cannot delete Foreign keys, hold Error on rename of./rusers/test2child to./rusers/# sql2-298-92 (errno: 152)

This was a bug in MySQL, but it is only an unfriendly part of MySQL.

Example:

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

The foreign key cannot be deleted, but the incorrect foreign key name is used. However, the error in MySQL is outrageous.
The correct error information must be queried as follows:

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 commandALTER TABLE ruler.test2child DROP FOREIGN KEY testCannot find a constraint with the given id "test".

In addition, other operations on Foreign keys are similar:

For example, when a foreign key is created, the following error occurs:

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:You have defined a SET NULL condition though some of thecolumns are defined as NOT NULL.

The test database version is:

5.2.0-falcon-alpha-community-nt

How to delete a foreign key:

// Delete the foreign key name and then the foreign key field (officially provided by mysql)

Example:

alter table task drop foreign key FK_Reference_7;alter table task drop column `assigned`;

The above is a summary of MySQL foreign key deletion issues introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.