我有以下代码:
ALTER TABLE users MODIFY id int unsigned;
会引发以下错误:
ERROR 1025 (HY000) at line 114: Error on rename of './mydb/#sql-146dd_1d' to './mydb/users' (errno: 150)
我很确定这是因为外键问题,但我想找到有关错误的更多细节。
我似乎记得我可以在mySQL命令行中输入一些内容,它会显示各种类型问题(包括外键问题)的最新错误列表,以及有关确切原因的更多详细信息(如涉及的表格)。有谁知道我在说什么?
答案 0 :(得分:3)
我认为你要找的是SHOW ENGINE INNODB STATUS
command(我假设是innodb引擎),它提供了最后一个外键错误。
mysql> CREATE TABLE `T1`(`id` int(10) unsigned NOT NULL AUTO_INCREMENT,PRIMARY KEY (`id`)) ENGINE=InnoDB;
mysql> CREATE TABLE `T2` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `refer_id` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `refer_id` (`refer_id`), CONSTRAINT `t2_id_to_t1_id` FOREIGN KEY (`refer_id`) REFERENCES `T1`.`id` ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
ERROR 1005 (HY000): Can't create table 'TEMP.T2' (errno: 150)
mysql> SHOW ENGINE INNODB STATUS;
[...]
------------------------
LATEST FOREIGN KEY ERROR
------------------------
130506 15:50:41 Error in foreign key constraint of table TEMP/T2: FOREIGN KEY (`refer_id`) REFERENCES `T1`.`id` ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB: Cannot resolve table name close to: ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB
[...]
mysql> CREATE TABLE `T2` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `refer_id` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `refer_id` (`refer_id`), CONSTRAINT `t2_id_to_t1_id` FOREIGN KEY (`refer_id`) REFERENCES `T1`(`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
Query OK, 0 rows affected (0.04 sec)
我故意在表T2创建语句中插入一个错误,以演示外键错误的输出(在本例中是模式解析)。
答案 1 :(得分:0)
您可能正在寻找SHOW WARNINGS
。