lundi 2 septembre 2019

How to alter onDelete('RESTRICT') to CASCADE

In laravel 5.8 app I create a migration with table :

{
    Schema::create('reserves', function (Blueprint $table) {
        $table->increments('id');

        $table->integer('storage_space_id')->unsigned()->nullable();
        $table->foreign('storage_space_id')->references('id')->on('storage_spaces')->onDelete('RESTRICT');

        $table->decimal('vat', 12, 2)->nullable();
        ...
        $table->timestamp( 'created_at')->useCurrent();

        $table->index(['storage_space_id', 'reserve_date'], 'reserves_storage_space_id_reserve_date_index');
        $table->index(['storage_space_id', 'reserve_out_date'], 'reserves_storage_space_id_reserve_out_date_index');

    });
}

and now deleting row from storage_spaces I get “Integrity constraint violation” error when there are related rows in reserves. I know that I need to alter onDelete to “CASCADE”, but I do not can in be done with migration ? If yes how ?

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire