Database:
MySQL
The models relationships are:
User hasMany Modules
Modules hasMany data
Migration:
Modules:
$table->foreignId(‘user_id’)->nullable()->references(‘id’)->on(‘users’)->nullOnDelete();
Data:
$table->foreignId(‘module_id’)->references(‘id’)->on(‘modules’)->onDelete(‘cascade’);
When user is deleted the module should still exist and the data models associated with it should be deleted.
My issue the data models is not deleting when the module relationship is set to NULL.
I am assuming it’s because the module model is not deleted and does not trigger the cascade on Data model.
I there a way to do this in migrations or will i have to manual clean up the data models?
Thanks for the help.
I am deleting the user using $user->delete()
The Module model is updated correctly but Data models still exist
Sindious is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.