Ian
07/13/2021, 8:52 AMmodel User {
id String @default(cuid())
@@id([id])
}
model Group {
id String @default(cuid())
@@id([id])
}
model Member {
group Group @relation(fields: [groupId], references: [id])
groupId String
user User @relation(fields: [id], references: [id])
id String
@@id([groupId, id])
}
When creating user only it works fine, no problem with the default generation value of cuid()
But
When creating group only it doesn't work it says Null constraint error for id both from API and PRISMA studio
Why does my default cuid doesnt work?
Current workaround use cuid npm packageRyan
07/13/2021, 9:47 AMmodel User {
id String @id @default(cuid())
groups Member[]
}
model Group {
id String @id @default(cuid())
users Member[]
}
model Member {
group Group @relation(fields: [groupId], references: [id])
groupId String
user User @relation(fields: [id], references: [id])
id String
@@id([groupId, id])
}
Are you using VSCode? If so, then I would suggest using this extension that will create the relations correctly.
As for creating a Group, it works fine for me on the latest version of Prisma i.e. 2.26.0. Could you update to the latest and check?Ian
07/13/2021, 3:20 PM