I'm getting the error:
Msg 1785, Level 16, State 0, Line 238
Introducing FOREIGN KEY constraint 'FK_Studios_Members_HeadId' on table 'Studios' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Below is a simplified version of the two tables I'm having problems with:
CREATE TABLE [Members]
(
[MemberId] int NOT NULL IDENTITY
)
CREATE TABLE [Studios]
(
[StudioId] int NOT NULL IDENTITY,
[HeadId] int,
[OwnerId] int,
CONSTRAINT [PK_Studios] PRIMARY KEY ([StudioId]),
CONSTRAINT [FK_Studios_Members_OwnerId]
FOREIGN KEY ([OwnerId]) REFERENCES [Members] ([MemberId])
ON DELETE SET NULL,
CONSTRAINT [FK_Studios_Members_HeadId]
FOREIGN KEY ([HeadId]) REFERENCES [Members] ([MemberId])
ON DELETE SET NULL
)
I found that if I switch the order of the two FK's, it will always error on the second one. I don't see why this will cause a cascading problem since both have the "ON DELETE SET NULL".
This is being generated by EF Core code-first, so I need the relationships and can't just hack in trigger in the backend.
What am I missing?