When designing database schemas, ensure relations and constraints are explicitly and correctly defined: 1. Every model must have a properly defined primary key:
When designing database schemas, ensure relations and constraints are explicitly and correctly defined:
model EmailAccount {
email String @id // Primary key, not just @unique
// OR
id String @id @default(cuid()) // UUID as primary key
email String @unique // Unique but not primary key
}
model EmailAccount {
accountId String @unique
account Account @relation(fields: [accountId], references: [id])
}
- digestSchedule Schedule?
- digestScheduleId String? @unique
+ digestSchedule Schedule? // Let Prisma handle the relation
// ✅ Better - includes distinguishing field @@unique([executedRuleId, actionType, targetIdentifier]) ```
Proper relation definitions improve schema clarity, prevent migration issues, and avoid runtime errors from phantom fields or missing constraints.
Enter the URL of a public GitHub repository