Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

Question:

say this is an example:

Use has time sheet configurations.

One of the user is project manager.

Project manager manages many departments.

 

User (1) - configuration (many)

User (1) - departments(many)

 

I used ' onDelete('cascade') in the configuration dedicated for the user. but I don't want to delete the department.

So is it okay to make a null?

Then how to make a null value ? in the migration file?

 

Solution:

You should be able to use onDelete('set null') in the foreign key relation, but it is important to make sure that the field is also set to nullable.

For example:

$table->unsignedInteger('user_id')->nullable();

$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon