php - Getting cannot truncate a table referenced in a foreign key constraint in Yii framework -


i'm getting cannot truncate table referenced in foreign key constraint in yii framework

i have tried below see in of answers still not working

yii::app()->db->createcommand('set foreign_key_checks=0')->execute(); $this->db->createcommand()->checkintegrity(false)->execute(); $this->getfixturemanager()->checkintegrity(false); 

i error below

database exception – yii\db\exception

sqlstate[42000]: syntax error or access violation: 1701 cannot truncate table referenced in foreign key constraint (yiibasic.educations, constraint fk_user foreign key (user_id) references yiibasic.users (id)) sql being executed was: truncate table users

error info: array (
[0] => 42000
[1] => 1701
[2] => cannot truncate table referenced in foreign key constraint
(yiibasic.educations, constraint fk_user foreign key (user_id) references yiibasic.users (id)) )

can 1 me correct it. can give best way of seeding data in yii coudn't tutorial same

you must first disable constraints : set foreign_key_checks = 0;

then truncate tables

then reactivate constraints : set foreign_key_checks = 1;


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -