Why this matters
`ON DELETE CASCADE` makes a single `DELETE` quietly recurse through dependent tables. Prefer `RESTRICT` / `NO ACTION` / `SET NULL` and explicit deletion code paths so deletions are visible at the call site.
Examples
Incorrect
CREATE TABLE t (
fid integer REFERENCES other(id) ON DELETE CASCADE
);ALTER TABLE t ADD CONSTRAINT fk FOREIGN KEY (fid) REFERENCES other(id) ON DELETE CASCADE;Correct
CREATE TABLE t (
fid integer REFERENCES other(id) ON DELETE RESTRICT
);ALTER TABLE t ADD CONSTRAINT fk FOREIGN KEY (fid) REFERENCES other(id) ON DELETE NO ACTION;Configure it
// eslint.config.js
import postgresql from "eslint-plugin-postgresql";
export default [
{
files: ["**/*.sql"],
languageOptions: {
parser: postgresql.configs.recommended.languageOptions.parser,
},
plugins: { postgresql },
rules: {
"postgresql/no-on-delete-cascade": "warn",
},
},
]; Options
Edit the SQL — only no-on-delete-cascade is enabled.
Pre-filled with the first incorrect example. Toggle off in the rule shelf to see how the diagnostic disappears.
Diagnostics
No issues found.
2 rules enabled.
Rule under test
no-on-delete-cascade — plus no-syntax-error as a safety net.