Unable to delete from many to many relationship due to FK constraint
I have the following schema,
Users
<> Teams
- many to many
usersOnTeams - table to hold this relationship
I'm currently unable to delete a Team
record due to the foreign key of the team still existing in the usersOnTeams
table record.
I know it has something to do with cascading deletes but I'm not sure how. Any help is appreciated.
5 Replies
The exact error msg:
first the delete values from the referenced tables
I see, so there is no way to do this in one query?
there is a way. see the below code
both does the same job on high level when you introduce relations (refer here: https://orm.drizzle.team/docs/rqb#foreign-keys)
so if you just remove
references(() => table.column)
you can delete them in a single query apparently. but id not recommend it thoDrizzle Queries - DrizzleORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind
Your other option is to add
onDelete: "cascade"
to the foreign key constrain if that is what you want