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!