1
當我執行下列SQL命令:錯誤在刪除的表外鍵約束
CREATE TABLE `TableA` (
`tableAId` INT(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`tableAId`)
);
CREATE TABLE `TableB` (
`tableBId` INT(11) NOT NULL AUTO_INCREMENT,
`tableAId` INT(11) DEFAULT NULL,
PRIMARY KEY (`tableBId`),
CONSTRAINT `FK_TABLE_A_ID` FOREIGN KEY (`tableAId`) REFERENCES `TableA` (`tableAId`)
);
ALTER TABLE `TableB`
RENAME TO `NewTableB`;
ALTER TABLE `TableA`
RENAME TO `NewTableA`,
CHANGE COLUMN `tableAId` `newTableAId` INT(11) NOT NULL AUTO_INCREMENT FIRST;
DROP TABLE IF EXISTS NewTableA;
DROP TABLE IF EXISTS NewTableB;
CREATE TABLE `TableA` (
`tableAId` INT(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`tableAId`)
);
我有最後一個命令(即CREATE TABLE TableA (...)
)以下錯誤:
ERREUR SQL( 1005):無法創建表'TableA'(errno:150)外部 關鍵約束不正確
而當我執行show engine innodb status
我:
------------------------
LATEST FOREIGN KEY ERROR
------------------------
130531 12:06:05 Error in foreign key constraint of table TableB:
there is no index in referenced table which would contain
the columns as the first columns, or the data types in the
referenced table do not match the ones in table. Constraint:
,
CONSTRAINT `FK_TABLE_A_ID` FOREIGN KEY (`tableAId`) REFERENCES `NewTableA` (`tableAId`)
你嘗試過在單獨的查詢執行重命名錶和'表A的重命名列'? – Stephan
聽起來像是一個bug。它在5.1.46上運行良好。你檢查了MySQL錯誤跟蹤器嗎? (http://bugs.mysql.com) –
例如,也許它與此bug有關:http://bugs.mysql.com/bug.php?id=64922 –