efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Support `ON DELETE SET DEFAULT`

Open Atulin opened this issue 2 months ago • 2 comments

What problem are you trying to solve?

I ran across this limitation when trying to automagically move content of users that delete their accounts to a Deleted User kind of an account. Most databases support it fairly easily, say

CREATE TABLE posts (
    id SERIAL PRIMARY KEY,
    content TEXT,
    user_id INTEGER DEFAULT 1 REFERENCES users(id) ON DELETE SET DEFAULT
);

Unfortunately, EF Core only supports cascade, set null, no action, restrict, and client set null.

Describe the solution you'd like

Add .SetDetault to the DeleteBehavior enum and generate appropriate SQL.

Atulin avatar Dec 07 '25 09:12 Atulin

I'm a bot. Here are possible related and/or duplicate issues (I may be wrong):

  • https://github.com/dotnet/efcore/issues/7530
  • https://github.com/dotnet/efcore/issues/12661

MihuBot avatar Dec 07 '25 09:12 MihuBot

Makes sense to me. Not sure what additional work this involves beyond adding the enum and corresponding change in MigrationsSqlGenerator (change tracking behavior, @AndriySvyryd?). Putting in the backlog for now.

roji avatar Dec 08 '25 11:12 roji