Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel migration : Remove onDelete('cascade') from existing foreign key

I have created a migration like this :

// ...
$table->foreign('a')->references('b')->on('c')->onDelete('cascade');
// ...

I want to remove the onDelete('cascade') in a new migration without breaking anything. How can I do that ?

like image 391
rap-2-h Avatar asked Jan 27 '15 09:01

rap-2-h


People also ask

What is onDelete (' cascade ') in laravel?

Use the ON DELETE CASCADE option to specify whether you want rows deleted in a child table when corresponding rows are deleted in the parent table. If you do not specify cascading deletes, the default behavior of the database server prevents you from deleting data in a table if other tables reference it.

What is Cascade in SQL?

CASCADE in SQL is used to simultaneously delete or update an entry from both the child and parent table. The keyword CASCADE is used as a conjunction while writing the query of ON DELETE or ON UPDATE.


1 Answers

You can try to remove the old foreign key and add then add a new one without onDelete:

$table->dropForeign(['a']);
$table->foreign('a')->references('b')->on('c');
like image 153
lukasgeiter Avatar answered Nov 04 '22 07:11

lukasgeiter