gpt4 book ai didi

php - yii迁移返回1215 mysql错误

转载 作者:行者123 更新时间:2023-11-29 12:56:10 34 4
gpt4 key购买 nike

一遍又一遍地搜索和检查我的代码后,现在我想问一下。
我有 2 个表 umessageureply,当我想将外键从 ureply 引用添加到 umessage 时,我得到了1215 mysql 错误。

文件m140602_080318_create_table_umessage.php中创建umessage表的代码:

public function safeUp()
{
/*
* Create table umessage, this is connection way between customer & seller about specific object
* Add foreign key to table user and it's column id with sender column
* Add foreign key to table object and it's column id with objId column
*/
$this->createTable('tbl_umessage', array(
'id' => 'pk',
'time' => 'INT(15) NOT NULL',
'body' => 'TEXT NOT NULL',
'status' => 'TINYINT NOT NULL DEFAULT 0',
'visibleToS' => 'TINYINT NOT NULL DEFAULT 0',
'visibleToR' => 'TINYINT NOT NULL DEFAULT 0',
'sender' => 'INT(11)',
'objId' => 'INT(11) NOT NULL',
), 'ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
}

文件m140602_080329_create_table_ureply.php中的代码创建ureply表:

public function safeUp()
{
/*
* Create table ureply which store all replies to exact message
* Add foreign key to table umessage and it's column id with msgId column
*/
$this->createTable('tbl_ureply', array(
'id' => 'pk',
'time' => 'INT(15) NOT NULL',
'body' => 'TEXT NOT NULL',
'isSender' => 'TINYINT NOT NULL DEFAULT 0',
'msgId' => 'INT(11) NOT NULL',
), 'ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');

$this->addForeignKey('fk_ureply_umessage', 'tbl_ureply', 'msgId', 'umessage', 'id', 'CASCADE', 'CASCADE');
}

1215 错误是由于添加 fk_ureply_umessage 外键而导致的,我找不到我的错误。任何帮助将不胜感激。提前致谢。

最佳答案

您在 addForeignKey 方法中出现错误:

$this->addForeignKey('fk_ureply_umessage', 'tbl_ureply', 'msgId', 'umessage', 'id', 'CASCADE', 'CASCADE');

外键引用的表应该是tbl_umessage而不是umessage:

$this->addForeignKey('fk_ureply_umessage', 'tbl_ureply', 'msgId', 'tbl_umessage', 'id', 'CASCADE', 'CASCADE');

关于php - yii迁移返回1215 mysql错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24031995/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com