D
D
Daniel2021-05-29 16:18:54
MySQL
Daniel, 2021-05-29 16:18:54

How to assign default value for onUpdate/onDelete in Laravel (MySQL)?

Is there a way to set somewhere, for example in configuration files, the default value for onUpdate and onDelete?
MySQL itself defaults to no action (equivalent to restrict). I need to put cascade for all onUpdate.
Or maybe there is something like this in MySQL itself in the database settings..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2021-06-06
@dostrog

It's not very clear what exactly you want to get. Something like this:

Schema::table('devices', function (Blueprint $table) {
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('car_id')->nullable()->constrained()->onDelete('set null');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question