Skip to content

Self-referencing schema failing to create first db item #23981

Closed Answered by EightArmCode
EightArmCode asked this question in Q&A
Discussion options

You must be logged in to vote

I think I found the issue. I removed the @unique directive from parentName. Since a parent can have multiple children, this was invalid. The final schema, should anyone care to see it:

model Leaf {
  name      String @id @unique
  parentName  String?
  description String
  parent    Leaf? @relation("LeafToLeaf", fields: [parentName], references: [name], onUpdate: Cascade, onDelete: Restrict)
  children  Leaf[] @relation("LeafToLeaf")
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by EightArmCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant