[英]Laravel 8.54 Migration and Seeding Cannot truncate a table referenced in a foreign key constraint
[英]Getting cannot truncate a table referenced in a foreign key constraint in Yii framework
我得到的不能截断Yii框架中外键约束中引用的表
我已经尝试了以下,我可以在一些答案中看到,但仍然无法正常工作
Yii::app()->db->createCommand('set foreign_key_checks=0')->execute();
$this->db->createCommand()->checkIntegrity(false)->execute();
$this->getFixtureManager()->checkIntegrity(false);
我得到如下错误
数据库异常 - yii \\ db \\ Exception
SQLSTATE [42000]:语法错误或访问冲突:1701无法截断外键约束引用的表( yiibasic
。 educations
,约束FK_user
外键( user_id
)参考yiibasic
。 users
( id
正在执行的SQL))为:截断表users
错误信息:数组(
[0] => 42000
[1] => 1701
[2] =>无法截断外键约束中引用的表
( yiibasic
。 educations
,约束FK_user
外键( user_id
)参考yiibasic
。 users
( id
)))
任何人都可以帮我纠正它。 你也可以在Yii中给出播种数据的最好方法我也不能得到一个好的教程
您必须先禁用约束: SET foreign_key_checks = 0;
然后截断你的表
然后重新激活约束: SET foreign_key_checks = 1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.