Exercise 3: Designing a Comment Model — Possible Solution =========================================================== model Comment { id Int @id @default(autoincrement()) body String createdAt DateTime @default(now()) postId Int post Post @relation(fields: [postId], references: [id], onDelete: Cascade) authorId Int? author User? @relation(fields: [authorId], references: [id], onDelete: SetNull) @@index([postId]) @@index([authorId]) } // and add the other sides: model Post { ... comments Comment[] } model User { ... comments Comment[] } Choices: post -> onDelete: Cascade A comment only makes sense under its post. If the post is deleted, its comments should go too; leaving them behind would create orphans nobody can see. author -> optional, onDelete: SetNull Guests can comment, so the relation must be optional anyway. If a user deletes their account, their comments stay, so the discussion still makes sense, but lose their link to the account (display them as "deleted user"). SetNull is also the default for optional relations; writing it out makes the intention clear. Both foreign keys are indexed, because you'll list comments by post and by author. WHY THIS WORKS AS AN ANSWER ------------------------------ It chooses each referential action from what the data means, not habit: comments depend on posts, but not on their authors' accounts.