Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add "ON DELETE CASCADE" to existing column in Laravel

I have user_id fk column in my table

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

I should add on cascade delete feature to this existing column. How can I do this?

like image 651
Farid Movsumov Avatar asked Nov 08 '14 18:11

Farid Movsumov


1 Answers

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'); 
like image 162
Farid Movsumov Avatar answered Sep 19 '22 14:09

Farid Movsumov