![](/img/trans.png)
[英]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.