Laravel Schema onDelete set null

In laravel 8 you can use:

$table->foreignId('forign_id')->nullable()->constrained("table_name")->cascadeOnUpdate()->nullOnDelete();

Reference

The different options are declared in class Illuminate\Database\Schema\ForeignKeyDefinition (see source).


  • This is a known issue in Laravel. More info about this here.

  • This feature is not supported in SQLite, see here

  • Also a topic that has a detailed showdown of this problem


If you want to set null on delete:

$table->...->onDelete('set null');

First make sure you set the foreign key field as nullable:

$table->integer('foreign_id')->unsigned()->nullable();