【发布时间】:2014-12-19 07:30:20
【问题描述】:
当我使用 migrate yii 添加这个外键时显示这个错误:
add foreign key fk_material_userprofile: material (insert_user_ID) references userprofile (userID)
...exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement:
SQLSTATE[HY000]: General error: 1215 Impossible d'ajouter des contraintes d'index externe. The SQL
statement executed was: ALTER TABLE `material` ADD CONSTRAINT `fk_material_userprofile` FOREIGN KEY
(`insert_user_ID`) REFERENCES `userprofile` (`userID`) ON DELETE CASCADE ON UPDATE RESTRICT' in
E:\framework\db\CDbCommand.php:358
这是我的代码:
public function up()
{
$this->addForeignKey("fk_newspaper", "materiallll", "newspaper_ID", "newspaper", "newspaper_ID", "CASCADE", "RESTRICT");
}
这是我的数据库:
CREATE TABLE IF NOT EXISTS `materiallll` (
`material_ID` int(11) NOT NULL AUTO_INCREMENT,
`newspaper_ID` tinyint(4) NOT NULL,
PRIMARY KEY (`material_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
请帮帮我。
【问题讨论】:
-
请将法语显示的错误翻译成英语。它可以帮助更快地获得答案。