Add "ON DELETE CASCADE" to existing column in Laravel
Drop foreign key first. Thanks to Razor for this tip
$table->dropForeign('answers_user_id_foreign');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
In my case, i'll need to put the col name in an array else that will be an error.
Schema::table('transactions', function (Blueprint $table) {
$table->dropForeign(['transactions_order_id_foreign']);
$table->foreign('order_id')
->references('id')->on('orders')
->onDelete('cascade')
->change();
});
mysql 5.7 ver
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');