Bug description
When I set db CONSTRAINT to CASCADE on delete and relation is marked as required in schema, prisma errors with
The change you are trying to make would violate the required relation 'UserToPost' between the `User` and `Post` models.
It works when I set the foreign key and the relation field as optional in prisma schema.
How to reproduce
- Set delete behaviour to cascade in db:
ALTER TABLE public.Post
DROP CONSTRAINT Post_authorId_fkey,
ADD CONSTRAINT Post_authorId_fkey
FOREIGN KEY (authorId)
REFERENCES public.User (id)
ON DELETE CASCADE
ON UPDATE CASCADE;
- create at least one User and one Post that belongs to him.
- try to delete that User with prisma client
Expected behavior
The user and all his posts should be deleted.
Prisma information
schema:
model User {
id Int @id @default(autoincrement())
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
author User @relation(fields: [authorId], references: [id])
authorId Int
}
Environment & setup
DB: Postgres 11.4
Prisma: 2.0.0-beta.2
Node: 12.2.0
Bug description
When I set db CONSTRAINT to CASCADE on delete and relation is marked as required in schema, prisma errors with
It works when I set the foreign key and the relation field as optional in prisma schema.
How to reproduce
Expected behavior
The user and all his posts should be deleted.
Prisma information
schema:
Environment & setup
DB: Postgres 11.4
Prisma: 2.0.0-beta.2
Node: 12.2.0