【发布时间】:2011-09-02 03:37:35
【问题描述】:
所以我正在尝试向我的一个表中添加一个新的外键:
ALTER TABLE `UserTransactions`.`ExpenseBackTransactions`
ADD CONSTRAINT `FK_EBTx_CustomAccountID`
FOREIGN KEY (`CustomAccountID` )
REFERENCES `UserTransactions`.`CustomAccounts` (`CustomAccountID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
ADD INDEX `FK_EBTx_CustomAccountID` (`CustomAccountID` ASC) ;
我不断收到以下错误:
Error Code: 1005
Can't create table './UserTransactions/#sql-187a_29.frm' (errno: 150)
过去我对这个表和其他表进行了相当多的更改,这是我第一次遇到这个问题。有什么想法是什么原因造成的吗?
更新
我的SHOW INNODB STATUS 错误:
------------------------
LATEST FOREIGN KEY ERROR
------------------------
110525 15:56:36 Error in foreign key constraint of table UserTransactions/#sql-187a_2c:
FOREIGN KEY (`CustomAccountID` )
REFERENCES `UserTransactions`.`CustomAccounts` (`CustomAccountID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION
, ADD INDEX `FK_EBTx_CustomAccountID` (`CustomAccountID` ASC):
Cannot resolve table name close to:
(`CustomAccountID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION
, ADD INDEX `FK_EBTx_CustomAccountID` (`CustomAccountID` ASC)
【问题讨论】:
-
SHOW INNODB STATUS说什么?两列是否具有相同的数据类型(和长度?)?数据库中是否已经有另一个具有该名称的键? -
FOREIGN KEY 仅支持 InnoDB dev.mysql.com/doc/refman/5.5/en/… 。检查这是否导致问题。
-
@Ibrahim:myisam 默默地忽略外键规范而不会出错。
标签: mysql foreign-keys mysql-error-1005