How to delete Foreigen key constraint from table in yii2? <p>In <strong>actionDelete</strong> I have write query for get fk from all table and create activeDataProvider.and write a foreach loop for geting one by one element.</p> <pre><code>$query = new \yii\db\Query; $query-&gt;select('practiceCode')-&gt;from('member','plan','offer','appointment','product','incentive','clinic','complaint') -&gt;where(['practiceCode' =&gt; $model-&gt;practiceCode])-&gt;all(); $query-&gt;createCommand(); $dataProvider= new ActiveDataProvider([ 'query' =&gt; $query, 'pagination' =&gt; false, ]); $models = $dataProvider-&gt;getModels(); if(count($models) &gt;= 1) { $memberModel = new Member(); foreach ($models as $k) { $k['deleted'] = 'Y'; //$memberModel-&gt;save(); $connection-&gt;createCommand()-&gt;update('member', ['deleted' =&gt; 'Y'], ['practiceCode' =&gt; $models['practiceCode']])-&gt;execute(); </code></pre> <p>Now it's work Doing same think for all table one by one</p> <pre><code> } return $this-&gt;redirect(['index']); </code></pre> <p>I am troubling with how save this Flag 'Y' in all table where this <strong>practiceCode</strong> as foreign key.Please help how to do....Thanks in advance </p>