Skip to content

Missing @unique attribute is not properly checked #99

@ymc9

Description

@ymc9

One-to-one relation requires one side of reference to be marked @unique. It's not checked today.

repro:

model User {
    id String @id @default(cuid())
    data UserData?
}

model UserData {
    id String @id @default(cuid())
    user User  @relation(fields: [userId], references: [id])
    userId String
}

Error:
Error parsing attribute "@relation": A one-to-one relation must use unique fields on the defining side. Either add an @unique attribute to the field userId, or change the relation to one-to-many.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions