Add “ON DELETE CASCADE” to existing column in Laravel

前端 未结 7 1632
借酒劲吻你
借酒劲吻你 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:02

    Use the unsigned function to user_id in the present migration:

    $table->interger('user_id')->unsigned();
    $table->foreign('user_id')->references('id')->on('table_name')->onDelete('cascade');
    

提交回复
热议问题