Exercise 1: Adding One-to-Many and One-to-One Relations — Possible Solution ============================================================================= schema.prisma (relation parts only; keep your other fields): model User { id Int @id @default(autoincrement()) email String @unique name String? profile Profile? posts Post[] } model Profile { id Int @id @default(autoincrement()) bio String? userId Int @unique user User @relation(fields: [userId], references: [id], onDelete: Cascade) } model Post { id Int @id @default(autoincrement()) title String slug String @unique authorId Int author User @relation(fields: [authorId], references: [id]) @@index([authorId]) } $ npx prisma migrate dev --name add-relations (existing posts have no author, so accept the reset in development — see the chapter's warning box) $ npx prisma generate Creating the data using foreign keys: const user = await prisma.user.create({ data: { email: "grace@example.com", name: "Grace" }, }); await prisma.profile.create({ data: { bio: "Compiler pioneer", userId: user.id }, }); await prisma.post.createMany({ data: [ { title: "First", slug: "first", authorId: user.id }, { title: "Second", slug: "second", authorId: user.id }, ], }); Try creating a second profile with the same userId: it fails with a P2002 unique constraint error, which is the one-to-one rule working. WHY THIS WORKS AS AN ANSWER ------------------------------ It declares both sides of each relation, uses @unique for one-to-one, indexes the posts' foreign key, and sets Cascade only on the profile, as the exercise asked.