当我执行以下 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`)