Open
Description
Problem Description
Oracle behaviour:
- ON UPDATE: Oracle does not support any
ON UPDATE
actions for foreign keys - ON DELETE: Oracle only supports
CASCADE
andSET NULL
actions
Currently, Bun sets NO ACTION
as the default for both OnUpdate
and OnDelete
in foreign key relations, which causes SQL errors when working with Oracle databases.
Expected Behavior
When using Oracle dialect, Bun should:
- Automatically set
OnUpdate
to empty/null (since Oracle doesn't support it) - Only allow
CASCADE
andSET NULL
forOnDelete
actions - Either throw a validation error or automatically clear unsupported
OnDelete
values
Current Behavior
Bun generates foreign key constraints with NO ACTION
for both OnUpdate
and OnDelete
, which fails on Oracle with errors like:
Caution
ORA-02000: missing CASCADE keyword
Example Code
Model Definition
type User struct {
ID int64 `bun:",pk,autoincrement"`
Name string
Emails []string
}
type Story struct {
ID int64 `bun:",pk,autoincrement"`
Title string
AuthorID int64
Author *User `bun:"rel:belongs-to,join:author_id=id"`
}
Generated SQL (Current - Fails on Oracle)
CREATE TABLE "stories" ("id" INTEGER GENERATED BY DEFAULT AS IDENTITY, "title" VARCHAR2(255), "author_id" INTEGER, PRIMARY KEY ("id"), FOREIGN KEY ("author_id") REFERENCES "users" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION