# One-to-one relations (Prisma ORM v7) (/docs/orm/v7/prisma-schema/data-model/relations/one-to-one-relations)

How to define and work with one-to-one relations in Prisma.

Location: ORM > v7 > Prisma Schema > Data Model > Relations > One-to-one relations

One-to-one (1-1) relations connect at most **one** record on each side. In this example, `User` and `Profile` have a 1-1 relation:

```prisma
model User {
  id      Int      @id @default(autoincrement())
  profile Profile?
}

model Profile {
  id     Int  @id @default(autoincrement())
  user   User @relation(fields: [userId], references: [id])
  userId Int  @unique // Foreign key with unique constraint
}
```

This expresses:

- A user can have zero or one profile
- A profile must always be connected to exactly one user

You can also reference a non-ID field with `@unique`:

```prisma
model Profile {
  id        Int    @id @default(autoincrement())
  user      User   @relation(fields: [userEmail], references: [email])
  userEmail String @unique
}
```

## Multi-field relations (relational databases only)

```prisma
model User {
  firstName String
  lastName  String
  profile   Profile?
  @@id([firstName, lastName])
}

model Profile {
  id            Int    @id @default(autoincrement())
  user          User   @relation(fields: [userFirstName, userLastName], references: [firstName, lastName])
  userFirstName String
  userLastName  String
  @@unique([userFirstName, userLastName])
}
```

## 1-1 in the database

In SQL, a 1-1 relation requires a `UNIQUE` constraint on the foreign key. Without this, it becomes a 1-n relation.

For MongoDB, documents reference each other by ID:

```json
// User
{ "_id": { "$oid": "60d58e130011041800d209e1" }, "name": "Bob" }
// Profile
{ "_id": "...", "bio": "I like drawing.", "userId": { "$oid": "60d58e130011041800d209e1" } }
```

## Required and optional 1-1 relation fields

The side _without_ a relation scalar must be optional:

```prisma
model User {
  id      Int      @id @default(autoincrement())
  profile Profile? // No relation scalar - must be optional
}
```

The side _with_ a relation scalar can be required or optional:

**Mandatory 1-1** (cannot create User without Profile):

```prisma
model User {
  id        Int     @id @default(autoincrement())
  profile   Profile @relation(fields: [profileId], references: [id])
  profileId Int     @unique
}
```

**Optional 1-1** (can create User without Profile):

```prisma
model User {
  id        Int      @id @default(autoincrement())
  profile   Profile? @relation(fields: [profileId], references: [id])
  profileId Int?     @unique
}
```

## Choosing which side stores the foreign key

In 1-1 relations, you can choose which side holds the `@relation` attribute and foreign key. Both approaches are valid:

**Option 1:** Foreign key on `Profile`

```prisma
model User {
  id      Int      @id @default(autoincrement())
  profile Profile?
}

model Profile {
  id     Int  @id @default(autoincrement())
  user   User @relation(fields: [userId], references: [id])
  userId Int  @unique
}
```

**Option 2:** Foreign key on `User`

```prisma
model User {
  id        Int      @id @default(autoincrement())
  profile   Profile? @relation(fields: [profileId], references: [id])
  profileId Int?     @unique
}

model Profile {
  id   Int   @id @default(autoincrement())
  user User?
}
```

## Related pages

- [`Many-to-many relations`](/guides/prisma-schema-v7-data-model-relations-many-to-many-relations): How to define and work with many-to-many relations in Prisma.
- [`One-to-many relations`](/guides/prisma-schema-v7-data-model-relations-one-to-many-relations): How to define and work with one-to-many relations in Prisma.
- [`Referential actions`](/guides/prisma-schema-v7-data-model-relations-referential-actions): Referential actions let you define the update and delete behavior of related models on the database level
- [`Relation mode`](/guides/prisma-schema-v7-data-model-relations-relation-mode): Manage relations between records with relation modes in Prisma
- [`Self-relations`](/guides/prisma-schema-v7-data-model-relations-self-relations): How to define and work with self-relations in Prisma.

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
