[GH-ISSUE #238] Issue: Syntax error in Prisma schema when using the admin plugin #25507

Closed
opened 2026-04-17 15:45:57 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @elbokh on GitHub (Oct 19, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/238

Hello everyone!

I encountered an issue when using the admin plugin in my auth.ts configuration. After adding the plugin and attempting to generate the Prisma schema via the CLI, I received a syntax error in the Session model within the schema.prisma file. Specifically, it failed due to the definition of multiple @relation attributes on the same field.

Here is the relevant part of the generated Session model:

model Session {
  id             String   @id
  expiresAt      DateTime
  ipAddress      String?
  userAgent      String?
  userId         String
  user           User     @relation(fields: [userId], references: [id], onDelete: Cascade) 
                          @relation(fields: [impersonatedBy], references: [id], onDelete: Cascade)
  impersonatedBy String?

  @@map("session")
}

Error:

Attribute "@relation" can only be defined once.

It seems that it is trying to define two relationships on the user field simultaneously, which is not allowed. This causes a syntax error because each field can only have one @relation attribute.

Steps to Reproduce:

  1. Add the admin plugin to the auth.ts configuration.
  2. Run npx @better-auth/cli generate generate the schema.
  3. Observe the schema generated for the Session model and the resulting error.

Environment

  • better-auth : 0.5.1-beta.5
  • prisma: 5.21.1

Is there a recommended way to handle this type of relationship, or does the admin plugin require an adjustment to the schema generation process?

Thanks for your help!

Originally created by @elbokh on GitHub (Oct 19, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/238 Hello everyone! I encountered an issue when using the admin plugin in my auth.ts configuration. After adding the plugin and attempting to generate the Prisma schema via the CLI, I received a syntax error in the Session model within the schema.prisma file. Specifically, it failed due to the definition of multiple `@relation` attributes on the same field. Here is the relevant part of the generated Session model: ``` model Session { id String @id expiresAt DateTime ipAddress String? userAgent String? userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) @relation(fields: [impersonatedBy], references: [id], onDelete: Cascade) impersonatedBy String? @@map("session") } ``` ### Error: `Attribute "@relation" can only be defined once.` It seems that it is trying to define two relationships on the user field simultaneously, which is not allowed. This causes a syntax error because each field can only have one `@relation` attribute. ### Steps to Reproduce: 1. Add the admin plugin to the auth.ts configuration. 2. Run `npx @better-auth/cli generate` generate the schema. 3. Observe the schema generated for the Session model and the resulting error. ### Environment - `better-auth` : `0.5.1-beta.5` - `prisma`: `5.21.1` Is there a recommended way to handle this type of relationship, or does the admin plugin require an adjustment to the schema generation process? Thanks for your help!
GiteaMirror added the locked label 2026-04-17 15:45:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25507