[GH-ISSUE #6296] 1.4.1 CLI generates duplicate relation names when multiple fields reference the same model #19105

Closed
opened 2026-04-15 17:53:37 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @NigelBreslaw on GitHub (Nov 25, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6296

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

test-better-auth.ts

This minimal better auth file will generate the invalid schema to show the issue. Here is the (invalid) file it generates.

test-schema.ts

Current vs. Expected behavior

It worked fine in 1.3.x

What version of Better Auth are you using?

1.4.1

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000",
    "release": "25.1.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.10 GB"
  },
  "node": {
    "version": "v24.11.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.1"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "19.2.0"
    },
    {
      "name": "hono",
      "version": "4.10.6"
    }
  ],
  "databases": [
    {
      "name": "better-sqlite3",
      "version": "12.4.6"
    },
    {
      "name": "drizzle",
      "version": "0.44.7"
    }
  ],
  "betterAuth": {
    "version": "1.3.34",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Other

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @NigelBreslaw on GitHub (Nov 25, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6296 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce [test-better-auth.ts](https://github.com/user-attachments/files/23745399/test-better-auth.ts) This minimal better auth file will generate the invalid schema to show the issue. Here is the (invalid) file it generates. [test-schema.ts](https://github.com/user-attachments/files/23745425/test-schema.ts) ### Current vs. Expected behavior It worked fine in 1.3.x ### What version of Better Auth are you using? 1.4.1 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000", "release": "25.1.0", "cpuCount": 10, "cpuModel": "Apple M1 Pro", "totalMemory": "16.00 GB", "freeMemory": "0.10 GB" }, "node": { "version": "v24.11.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.1" }, "frameworks": [ { "name": "react", "version": "19.2.0" }, { "name": "hono", "version": "4.10.6" } ], "databases": [ { "name": "better-sqlite3", "version": "12.4.6" }, { "name": "drizzle", "version": "0.44.7" } ], "betterAuth": { "version": "1.3.34", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-15 17:53:37 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 25, 2025):

It looks like the 1.4.1 CLI isn’t handling multiple fields referencing the same model in a unique way, causing duplicate relation names that weren’t an issue in 1.3.x. As a troubleshooting step, you might try explicitly providing unique aliases for each relation field in your schema configuration so that the schema generator doesn’t conflict on names. If that workaround isn’t feasible or doesn’t resolve the issue, please consider rolling back to 1.3.x or filing a detailed bug report with a minimal reproduction so our team can investigate further [1].

Tag @better-auth-agent if you would like an answer from the Agent. Could you let me know if the alias workaround helps in your case?

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3575133843 --> @better-auth-agent[bot] commented on GitHub (Nov 25, 2025): It looks like the 1.4.1 CLI isn’t handling multiple fields referencing the same model in a unique way, causing duplicate relation names that weren’t an issue in 1.3.x. As a troubleshooting step, you might try explicitly providing unique aliases for each relation field in your schema configuration so that the schema generator doesn’t conflict on names. If that workaround isn’t feasible or doesn’t resolve the issue, please consider rolling back to 1.3.x or filing a detailed bug report with a minimal reproduction so our team can investigate further [[1]](https://github.com/better-auth/better-auth/issues/4125). Tag @better-auth-agent if you would like an answer from the Agent. Could you let me know if the alias workaround helps in your case? <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Nov 25, 2025):

Hi @NigelBreslaw! I'm Dosu and I’m helping the better-auth team.

This is a confirmed regression in Better Auth 1.4.x: the CLI now generates duplicate relation names when multiple fields reference the same model, because the schema generators (for both Prisma and Drizzle) use the referenced model's name (lowercased or pluralized) for relation fields without checking for uniqueness. This leads to invalid schemas if two or more fields point to the same model [source, source].

There’s no config or built-in workaround in 1.4.1; you’ll need to manually rename duplicate relation fields in the generated schema before using it [source]. This issue is tracked and acknowledged by maintainers, and there’s ongoing discussion about adding relation name customization in future releases. For now, keep an eye on updates or patch your schema manually [source, source]. If you want technical pointers for a local patch, let me know!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3575162408 --> @dosubot[bot] commented on GitHub (Nov 25, 2025): <!-- Greeting --> Hi @NigelBreslaw! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a confirmed regression in Better Auth 1.4.x: the CLI now generates duplicate relation names when multiple fields reference the same model, because the schema generators (for both Prisma and Drizzle) use the referenced model's name (lowercased or pluralized) for relation fields without checking for uniqueness. This leads to invalid schemas if two or more fields point to the same model [[source](https://github.com/better-auth/better-auth/blob/cb5c2fc2604090247f8bb9a33eae03a5fdc1ab14/packages/cli/src/generators/prisma.ts#L11-L434), [source](https://github.com/better-auth/better-auth/blob/cb5c2fc2604090247f8bb9a33eae03a5fdc1ab14/packages/cli/src/generators/drizzle.ts#L284-L388)]. There’s no config or built-in workaround in 1.4.1; you’ll need to manually rename duplicate relation fields in the generated schema before using it [[source](https://github.com/better-auth/better-auth/issues/6262)]. This issue is tracked and acknowledged by maintainers, and there’s ongoing discussion about adding relation name customization in future releases. For now, keep an eye on updates or patch your schema manually [[source](https://github.com/better-auth/better-auth/issues/6231), [source](https://github.com/better-auth/better-auth/issues/6198)]. If you want technical pointers for a local patch, let me know! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b0f11389-65ce-48ad-b1cc-44c75f5791a9?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b0f11389-65ce-48ad-b1cc-44c75f5791a9?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b0f11389-65ce-48ad-b1cc-44c75f5791a9?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b0f11389-65ce-48ad-b1cc-44c75f5791a9?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b0f11389-65ce-48ad-b1cc-44c75f5791a9?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b0f11389-65ce-48ad-b1cc-44c75f5791a9?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b0f11389-65ce-48ad-b1cc-44c75f5791a9?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20confirmed%20regression%20in%20Better%20Auth%201.4.x%3A%20the%20CLI%20now%20generates%20duplicate%20relation%20names%20when%20multiple%20fields%20reference%20the%20same%20model%2C%20because%20the%20schema%20generators%20%28for%20both%20Prisma%20and%20Drizzle%29%20use%20the%20referenced%20model%27s%20name%20%28lowercased%20or%20pluralized%29%20for%20relation%20fields%20without%20checking%20for%20uniqueness.%20This%20leads%20to%20invalid%20schemas%20if%20two%20or%20more%20fields%20point%20to%20the%20same%20model%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/cb5c2fc2604090247f8bb9a33eae03a5fdc1ab14/packages/cli/src/generators/prisma.ts%23L11-L434%29%2C%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/cb5c2fc2604090247f8bb9a33eae03a5fdc1ab14/packages/cli/src/generators/drizzle.ts%23L284-L388%29%5D.%0A%0AThere%E2%80%99s%20no%20config%20or%20built-in%20workaround%20in%201.4.1%3B%20you%E2%80%99ll%20need%20to%20manually%20rename%20duplicate%20relation%20fields%20in%20the%20generated%20schema%20before%20using%20it%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/6262%29%5D.%20This%20issue%20is%20tracked%20and%20acknowledged%20by%20maintainers%2C%20and%20there%E2%80%99s%20ongoing%20discussion%20about%20adding%20relation%20name%20customization%20in%20future%20releases.%20For%20now%2C%20keep%20an%20eye%20on%20updates%20or%20patch%20your%20schema%20manually%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/6231%29%2C%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/6198%29%5D.%20If%20you%20want%20technical%20pointers%20for%20a%20local%20patch%2C%20let%20me%20know%21)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6296)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19105