Add “ON DELETE CASCADE” to existing column in Laravel

前端 未结 7 1648
借酒劲吻你
借酒劲吻你 2021-02-04 23:52

I have user_id fk column in my table

$table->foreign(\'user_id\')->references(\'id\')->on(\'users\');

I should add on cascade

7条回答
  •  无人共我
    2021-02-05 00:10

    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

提交回复
热议问题