Delete NoAction
and Delete Restrict
are, almost, the same thing. See the important part: "both of these options cause referential constraints to be enforced".
In a relational database, referential constraint (or referential integrity) means that a value in a foreign key should exist on the referenced table, they cannot be a value in a foreign key that not exists in the referenced table. (Thank you, @IvanStoev, about notice me to include this content)
Quoting Impact on database schema MS docs:
The behaviors of ON DELETE NO ACTION
(the database default) and ON DELETE RESTRICT
in relational databases are typically either identical or very similar. Despite what NO ACTION
may imply, both of these options cause referential constraints to be enforced. The difference, when there is one, is when the database checks the constraints. Check your database documentation for the specific differences between ON DELETE NO ACTION and ON DELETE RESTRICT on your database system.
SQL Server doesn't support ON DELETE RESTRICT, so ON DELETE NO ACTION is used instead.
The only values that will cause cascading behaviors on the database are Cascade
and SetNull
. All other values will configure the database to not cascade any changes.
The following table shows the result of each OnDelete value on the foreign key constraint created by EF Core migrations or EnsureCreated:
DeleteBehavior |
Impact on database schema |
Cascade |
ON DELETE CASCADE |
Restrict |
ON DELETE RESTRICT |
NoAction |
database default |
SetNull |
ON DELETE SET NULL |
ClientSetNull |
database default |
ClientCascade |
database default |
ClientNoAction |
database default |