New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete of "parent" should not be prevented if it will cascade delete "children" on required relations #4650
Comments
@pantharshit00 if you have time to create a repro 🙏 |
So I wrote a repro here: https://github.com/Sytten/repro-prisma-4650 |
Hey, Thanks for the reproduction here. I can confirm this. I also made a reproduction for this yesterday but forgot to post it, you did a better one here today so we will use that. Thanks again :) |
The work around for now is using paljs plugin Delete: https://paljs.com/plugins/delete/ |
Thanks for the very helpful reproduction @Sytten! You can workaround this by making the Calendar optional: model Calendar {
id String @id @default(cuid())
events CalendarEvent[]
}
model CalendarEvent {
- calendar Calendar @relation(fields: [calendarId], references: [id])
+ calendar Calendar? @relation(fields: [calendarId], references: [id])
calendarId String
id String @id @default(cuid())
} We have a guide that discusses this in more detail: https://www.prisma.io/docs/guides/general-guides/database-workflows/cascading-deletes/postgresql However, I don't think the cascade settings shouldn't depend on optionality. I'll talk to the team about fixing this up. |
@matthewmueller Looking at the queries it does, it checks if any relation would be affected. I our case it runs 6 queries before the delete so this very wasteful and not necessary since the DB already ensure integrity with the cascade setting. |
Looks like this one is unfortunately blocked by #2810. We have this check to maintain data integrity when you have a required relation without cascade delete on the underlying database. It will also be needed for Mongo soon. Since we don't have state in the schema about the database's cascade settings, we can't turn this check on and off accordingly. We'll revisit this one after #2810. In the meantime, optional relations or Ahmed's paljs plugin is the way to go. Sorry about that! |
This should be now possible to do with prisma/prisma-engines#1947 Instructions on how to use this, and a place to give feedback: #7816 |
This has now been released as a preview feature flag. You can read about it in the release notes for 2.26.0: https://github.com/prisma/prisma/releases/tag/2.26.0 If you have any feedback, please use this issue: #7816 |
Bug description
Consider the simplified schema:
When trying to delete calendar I get:
This is contrary to what the doc says on the matter https://www.prisma.io/docs/guides/general-guides/database-workflows/cascading-deletes/postgresql
How to reproduce
Expected behavior
You should be allowed to delete the calendar and let the DB delete the children objects.
This is a somewhat new behaviour because I remember doing that successfully in a previous version.
Prisma information
I tested on Postgres, but probably is also valid for other databases.
The text was updated successfully, but these errors were encountered: