我正在尝试向我的一个表格中添加一个新的外键,如下所示:
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
显示了什么?这两列的数据类型(和长度)是否相同?数据库中是否已经有另一个使用该名称的键? - Konerak