I have the following tables. I have several dashboards. A dashboard can have several breakpoints. Each breakpoint has several widgets. If the dashboard is deleted, then all of the breakpoints for that dashboard also need to be deleted. When the breakpoint is deleted, the widgets for that breakpoint need to be deleted also.
CREATE TABLE dashboards (
id INT IDENTITY(1,1) PRIMARY KEY,
...
);
CREATE TABLE breakpoints (
id INT IDENTITY(1,1) PRIMARY KEY,
dashboardId INT REFERENCES dashboards(id) ON DELETE CASCADE,
...
);
CREATE TABLE widgets (
id INT IDENTITY(1,1) PRIMARY KEY,
breakpointId INT REFERENCES breakpoints(id) ON DELETE CASCADE,
...
);
When I try to run the above code, I get an error:
Introducing FOREIGN KEY constraint
'FK__breakpoints__6225902D'
on table'widgets'
may cause cycles or multiple cascade paths. SpecifyON DELETE NO ACTION
orON UPDATE NO ACTION
, or modify other FOREIGN KEY constraints.
If I change it to NO ACTION
then I don't get an error, but I need it to cascade.
How would I go about fixing this?