nextauthjs / nextauthjs/next-auth

MySQL Prisma schema has an inconsistent Account relation

Open Beginner friendly
#13,472 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

The MySQL schema in the Prisma adapter documentation defines an inconsistent relationship between User and Account:

model User {
  accounts Account[]
}

model Account {
  userId String @unique
  user   User?  @relation(fields: [userId], references: [id])
}

There are two issues:

  1. userId is required, but the corresponding user relation is marked as optional.
  2. userId @unique prevents multiple accounts from referencing the same user. This conflicts with accounts Account[] and prevents users from linking
    multiple providers.

The relationship should instead be:

model User {
  accounts Account[]
}

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

The existing @@unique([provider, providerAccountId]) constraint should remain because it uniquely identifies each provider account.

Is there any context that might help us understand?

The PostgreSQL, SQLite, and MongoDB examples use a required, non-unique userId and a required User relation.

Aligning the MySQL example with them accurately models the intended one-to-many relationship: every account belongs to one user, while one user may link
multiple provider accounts, such as GitHub and Google.

Does the docs page already exist? Please link to it.

https://authjs.dev/getting-started/adapters/prisma#schema

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the Prisma adapter documentation at the linked authjs.dev page and locate the MySQL schema example. Compare it with the PostgreSQL, SQLite, and MongoDB examples, then update the Account relation to match the stated one-to-many relationship while keeping @@unique([provider, providerAccountId]). Done when the MySQL example permits multiple accounts per user and uses a required user relation.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql
Domain
databases, documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.