
On delete set foreign id column value null using migration in laravel 8
On delete set foreign id column value null using migration in laravel 8
With this article, we’ll look at some examples of how to address the "On delete set foreign id column value null using migration in laravel 8" problem.
Sometimes we have to create a column with foreign id in the table which we have to set null on delete the parent table row (related table row). Like if you have a column discount_id (foreign ID) in a table which is related to discount table id. On delete discount table records the column value of discount_id will be set null.-
On delete set null foreign id column in migration in laravel 8
$table->foreignId('discount_id')->nullable()->constrained()->onDelete('set null');
It will set the null value to the foreignId column in the table on delete the parent table records. Like on delete discount table records which is the parent table it will set value of foreign id column (discount_id) to null.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- How to pass query string with pagination in laravel
- Include External CSS and JS file in Laravel
- Recursive function example code PHP Laravel
- How to add script on specific view file in laravel while extending layout
- Check if Relationship Method Exists in Laravel
- Drop foreign key column in Laravel using migration
- How to get query string value in laravel
- JQuery each loop on json response after ajax in laravel
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- Create record with unique slug in laravel
- How to generate .env file for laravel?
- Update record after find method in lavavel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Page loader in laravel
- Use withCount() to Calculate Child Relationship Records
- How to add foreign key in laravel using migration
- External link not working in laravel blade
- How to get date from created_at field in laravel
- Return redirect laravel not working
- How to get last month records in Laravel
- Call to a member function getRelationExistenceQuery() on array in Laravel
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- PhpMyAdmin - Error The mysqli extension is missing
- Laravel insert query not working