Ad
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!
Ad
Answer
You can create a new migration and then drop the foreign key and recreate it:
Schema::table('reserves', function (Blueprint $table) {
$table->dropForeign(['storage_space_id']);
$table->foreign('storage_space_id')
->references('id')
->on('storage_spaces')
->onDelete('cascade');
});
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad