Overriding the default value of account.modelName in the config doesn't actually work - default model name is still used in login #2415

Closed
opened 2026-03-13 09:52:29 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @TheMightyDev on GitHub (Nov 28, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. With the configuration below - that overrides the default model names so they be in PascalCase instead of the usual all lowercase (E.g. instead of "account" to "Account").

Exempt from schema.prisma:

/// Necessary for Better auth
model Account {
  id                    String    @id
  // Map existing `providerAccountId` (from NextAuth.js) field to Better Auth's `accountId`
  accountId             String    @map("providerAccountId")
  // Map existing `provider` (from NextAuth.js) field to Better Auth's `providerId`
  providerId            String    @map("provider")
  userId                String
  user                  User      @relation(fields: [userId], references: [id], onDelete: Cascade)
  // Map existing `access_token` (from NextAuth.js) field to Better Auth's `accessToken`
  accessToken           String?   @map("access_token")
  // Map existing `refresh_token` (from NextAuth.js) field to Better Auth's `refreshToken`
  refreshToken          String?   @map("refresh_token")
  // Map existing `id_token` (from NextAuth.js) field to Better Auth's `idToken`
  idToken               String?   @map("id_token")
  // Map existing `expires_at` (from NextAuth.js) field to Better Auth's `accessTokenExpiresAt`
  accessTokenExpiresAt  DateTime? @map("expires_at")
  refreshTokenExpiresAt DateTime?
  scope                 String?
  password              String?
  createdAt             DateTime  @default(now())
  updatedAt             DateTime  @updatedAt

  @@index([userId])
}
  1. Then, if I try to login on the client side, using the following code:
const response = await authClient.signIn.phoneNumber({
	phoneNumber: values.phoneNumber,
	password: values.password,
	rememberMe: true,
});

I get the error:

# SERVER_ERROR:  Error [PrismaClientKnownRequestError]: 
Invalid `prisma.account.findMany()` invocation:

The table `public.account` does not exist in the current database.
    at ei.handleRequestError (PROJECT_DIR\.next\dev\server\chunks\[root-of-the-server]__e4de5669._.js:7327:19)
{    
  code: 'P2021',
  meta: [Object],
  clientVersion: '6.14.0'
}

Current vs. Expected behavior

Because I explicitly specified that the model name for account should be "Account" - it should attempt to use the "Account" model (and not "account" in lowercase):

Image

What version of Better Auth are you using?

1.3.34

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 10 Home",
    "release": "10.0.19045",
    "cpuCount": 8,
    "cpuModel": "Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz",
    "totalMemory": "7.82 GB",
    "freeMemory": "0.53 GB"
  },
  "node": {
    "version": "v22.11.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.8.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "^16.0.5"
    },
    {
      "name": "react",
      "version": "^19.2.0"
    }
  ],
  "databases": [
    {
      "name": "@prisma/client",
      "version": "^6.14.0"
    }
  ],
  "betterAuth": {
    "version": "^1.3.34",
    "config": null
  }
}

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

Backend, Client

Auth config (if applicable)

import { betterAuth, type BetterAuthOptions } from "better-auth"
import { prismaAdapter } from "better-auth/adapters/prisma";
import { phoneNumber } from "better-auth/plugins";
import { db } from "~/server/db";

const options = {
  plugins: [phoneNumber()],
} as const satisfies BetterAuthOptions;

export const auth = betterAuth({
  emailAndPassword: {  
    enabled: false
  },
  user: {
    modelName: "User",
    deleteUser: {
      enabled: false,
    }
  },
  account: {
    modelName: "Account",
  },
  verification: {
    modelName: "Verification",
  },
  session: {
    modelName: "Session",
  },
  database: prismaAdapter(db, {
    provider: "postgresql",
  }),
});

Additional context

No response

Originally created by @TheMightyDev on GitHub (Nov 28, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. With the configuration below - that overrides the default model names so they be in `PascalCase` instead of the usual all lowercase (E.g. instead of `"account"` to `"Account"`). Exempt from `schema.prisma`: ```prisma /// Necessary for Better auth model Account { id String @id // Map existing `providerAccountId` (from NextAuth.js) field to Better Auth's `accountId` accountId String @map("providerAccountId") // Map existing `provider` (from NextAuth.js) field to Better Auth's `providerId` providerId String @map("provider") userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) // Map existing `access_token` (from NextAuth.js) field to Better Auth's `accessToken` accessToken String? @map("access_token") // Map existing `refresh_token` (from NextAuth.js) field to Better Auth's `refreshToken` refreshToken String? @map("refresh_token") // Map existing `id_token` (from NextAuth.js) field to Better Auth's `idToken` idToken String? @map("id_token") // Map existing `expires_at` (from NextAuth.js) field to Better Auth's `accessTokenExpiresAt` accessTokenExpiresAt DateTime? @map("expires_at") refreshTokenExpiresAt DateTime? scope String? password String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([userId]) } ``` 2. Then, if I try to login on the client side, using the following code: ```typescript const response = await authClient.signIn.phoneNumber({ phoneNumber: values.phoneNumber, password: values.password, rememberMe: true, }); ``` I get the error: ```txt # SERVER_ERROR: Error [PrismaClientKnownRequestError]: Invalid `prisma.account.findMany()` invocation: The table `public.account` does not exist in the current database. at ei.handleRequestError (PROJECT_DIR\.next\dev\server\chunks\[root-of-the-server]__e4de5669._.js:7327:19) { code: 'P2021', meta: [Object], clientVersion: '6.14.0' } ``` ### Current vs. Expected behavior Because I explicitly specified that the model name for account should be "Account" - it should attempt to use the "Account" model (and not "account" in lowercase): <img width="262" height="308" alt="Image" src="https://github.com/user-attachments/assets/87de9d19-c459-4257-a6b3-d492d0cbc17b" /> ### What version of Better Auth are you using? 1.3.34 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 10 Home", "release": "10.0.19045", "cpuCount": 8, "cpuModel": "Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz", "totalMemory": "7.82 GB", "freeMemory": "0.53 GB" }, "node": { "version": "v22.11.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.8.2" }, "frameworks": [ { "name": "next", "version": "^16.0.5" }, { "name": "react", "version": "^19.2.0" } ], "databases": [ { "name": "@prisma/client", "version": "^6.14.0" } ], "betterAuth": { "version": "^1.3.34", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript import { betterAuth, type BetterAuthOptions } from "better-auth" import { prismaAdapter } from "better-auth/adapters/prisma"; import { phoneNumber } from "better-auth/plugins"; import { db } from "~/server/db"; const options = { plugins: [phoneNumber()], } as const satisfies BetterAuthOptions; export const auth = betterAuth({ emailAndPassword: { enabled: false }, user: { modelName: "User", deleteUser: { enabled: false, } }, account: { modelName: "Account", }, verification: { modelName: "Verification", }, session: { modelName: "Session", }, database: prismaAdapter(db, { provider: "postgresql", }), }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 09:52:29 -05:00
Author
Owner

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

Thanks for reporting this issue! It appears that even though you’ve overridden the model name in your configuration to "Account", the internal Prisma adapter is still referencing the default lowercase table name. One troubleshooting step is to verify that your Prisma migrations have been run successfully and that the actual table in your database is indeed named "Account" (matching the case you specified). Additionally, double-check that any implicit references in the adapter code or schema mapping are updated accordingly for uppercase names. Our configuration options are meant to support custom model names, so if the issue persists it could indicate that the adapter isn’t properly propagating the override.

Could you verify your migration logs and ensure that the table was created with the correct name? Also, are other model name overrides working as expected in your project?

tag @better-auth-agent if you would like an answer from the Agent

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 28, 2025): Thanks for reporting this issue! It appears that even though you’ve overridden the model name in your configuration to "Account", the internal Prisma adapter is still referencing the default lowercase table name. One troubleshooting step is to verify that your Prisma migrations have been run successfully and that the actual table in your database is indeed named "Account" (matching the case you specified). Additionally, double-check that any implicit references in the adapter code or schema mapping are updated accordingly for uppercase names. Our configuration options are meant to support custom model names, so if the issue persists it could indicate that the adapter isn’t properly propagating the override. Could you verify your migration logs and ensure that the table was created with the correct name? Also, are other model name overrides working as expected in your project? tag @better-auth-agent if you would like an answer from the Agent <!-- 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 28, 2025):

This is a known issue that has affected multiple users: setting a custom modelName in the Better Auth config (like "Account") sometimes doesn't work as expected, and the system still tries to use the default lowercase model name (like "account"), leading to errors such as prisma.account.findMany() failing when only Account exists in your Prisma client and database. This usually happens if the Prisma model name and the Better Auth config modelName don't match exactly, since Prisma client properties are case-sensitive and must match the model name as defined in your Prisma schema (e.g., PascalCase Account) [1] [2] [3].

Better Auth's internal schema and adapter logic are designed to respect the modelName override, but if there's any mismatch or if the Prisma client hasn't been regenerated after schema changes, you'll see this error. The most reliable workaround is to ensure that your Prisma model name (in schema.prisma) and the modelName in your Better Auth config are identical and case-sensitive (e.g., both should be Account, not account or accounts). Using only @@map to rename the table in the database is not enough—it's the Prisma model name that matters for the client [1] [2].

If you've already done this and still see the issue, make sure to run npx prisma generate after any schema changes. Also, recent versions of Better Auth have improved model name resolution, so if you're not on the latest version, consider upgrading.

In summary: always match the modelName in your Better Auth config to the Prisma model name (PascalCase), not the table name or a lowercase variant, and regenerate your Prisma client after changes. This should resolve the issue in most cases.

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

@dosubot[bot] commented on GitHub (Nov 28, 2025): <!-- Answer --> This is a known issue that has affected multiple users: setting a custom `modelName` in the Better Auth config (like `"Account"`) sometimes doesn't work as expected, and the system still tries to use the default lowercase model name (like `"account"`), leading to errors such as `prisma.account.findMany()` failing when only `Account` exists in your Prisma client and database. This usually happens if the Prisma model name and the Better Auth config `modelName` don't match exactly, since Prisma client properties are case-sensitive and must match the model name as defined in your Prisma schema (e.g., PascalCase `Account`) [[1]](https://github.com/better-auth/better-auth/issues/2713) [[2]](https://github.com/better-auth/better-auth/issues/1901) [[3]](https://github.com/better-auth/better-auth/issues/2937). Better Auth's internal schema and adapter logic are designed to respect the `modelName` override, but if there's any mismatch or if the Prisma client hasn't been regenerated after schema changes, you'll see this error. The most reliable workaround is to ensure that your Prisma model name (in `schema.prisma`) and the `modelName` in your Better Auth config are identical and case-sensitive (e.g., both should be `Account`, not `account` or `accounts`). Using only `@@map` to rename the table in the database is not enough—it's the Prisma model name that matters for the client [[1]](https://github.com/better-auth/better-auth/issues/2713) [[2]](https://github.com/better-auth/better-auth/issues/1901). If you've already done this and still see the issue, make sure to run `npx prisma generate` after any schema changes. Also, recent versions of Better Auth have improved model name resolution, so if you're not on the latest version, consider upgrading. In summary: always match the `modelName` in your Better Auth config to the Prisma model name (PascalCase), not the table name or a lowercase variant, and regenerate your Prisma client after changes. This should resolve the issue in most cases. <!-- 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/7496131c-66fa-40cf-94d7-21775429fc58?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7496131c-66fa-40cf-94d7-21775429fc58?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7496131c-66fa-40cf-94d7-21775429fc58?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7496131c-66fa-40cf-94d7-21775429fc58?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7496131c-66fa-40cf-94d7-21775429fc58?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7496131c-66fa-40cf-94d7-21775429fc58?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7496131c-66fa-40cf-94d7-21775429fc58?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%20known%20issue%20that%20has%20affected%20multiple%20users%3A%20setting%20a%20custom%20%60modelName%60%20in%20the%20Better%20Auth%20config%20%28like%20%60%22Account%22%60%29%20sometimes%20doesn%27t%20work%20as%20expected%2C%20and%20the%20system%20still%20tries%20to%20use%20the%20default%20lowercase%20model%20name%20%28like%20%60%22account%22%60%29%2C%20leading%20to%20errors%20such%20as%20%60prisma.account.findMany%28%29%60%20failing%20when%20only%20%60Account%60%20exists%20in%20your%20Prisma%20client%20and%20database.%20This%20usually%20happens%20if%20the%20Prisma%20model%20name%20and%20the%20Better%20Auth%20config%20%60modelName%60%20don%27t%20match%20exactly%2C%20since%20Prisma%20client%20properties%20are%20case-sensitive%20and%20must%20match%20the%20model%20name%20as%20defined%20in%20your%20Prisma%20schema%20%28e.g.%2C%20PascalCase%20%60Account%60%29%20%5B%5B1%5D%5D%28https%3A//github.com/better-auth/better-auth/issues/2713%29%20%5B%5B2%5D%5D%28https%3A//github.com/better-auth/better-auth/issues/1901%29%20%5B%5B3%5D%5D%28https%3A//github.com/better-auth/better-auth/issues/2937%29.%0A%0ABetter%20Auth%27s%20internal%20schema%20and%20adapter%20logic%20are%20designed%20to%20respect%20the%20%60modelName%60%20override%2C%20but%20if%20there%27s%20any%20mismatch%20or%20if%20the%20Prisma%20client%20hasn%27t%20been%20regenerated%20after%20schema%20changes%2C%20you%27ll%20see%20this%20error.%20The%20most%20reliable%20workaround%20is%20to%20ensure%20that%20your%20Prisma%20model%20name%20%28in%20%60schema.prisma%60%29%20and%20the%20%60modelName%60%20in%20your%20Better%20Auth%20config%20are%20identical%20and%20case-sensitive%20%28e.g.%2C%20both%20should%20be%20%60Account%60%2C%20not%20%60account%60%20or%20%60accounts%60%29.%20Using%20only%20%60%40%40map%60%20to%20rename%20the%20table%20in%20the%20database%20is%20not%20enough%E2%80%94it%27s%20the%20Prisma%20model%20name%20that%20matters%20for%20the%20client%20%5B%5B1%5D%5D%28https%3A//github.com/better-auth/better-auth/issues/2713%29%20%5B%5B2%5D%5D%28https%3A//github.com/better-auth/better-auth/issues/1901%29.%0A%0AIf%20you%27ve%20already%20done%20this%20and%20still%20see%20the%20issue%2C%20make%20sure%20to%20run%20%60npx%20prisma%20generate%60%20after%20any%20schema%20changes.%20Also%2C%20recent%20versions%20of%20Better%20Auth%20have%20improved%20model%20name%20resolution%2C%20so%20if%20you%27re%20not%20on%20the%20latest%20version%2C%20consider%20upgrading.%0A%0AIn%20summary%3A%20always%20match%20the%20%60modelName%60%20in%20your%20Better%20Auth%20config%20to%20the%20Prisma%20model%20name%20%28PascalCase%29%2C%20not%20the%20table%20name%20or%20a%20lowercase%20variant%2C%20and%20regenerate%20your%20Prisma%20client%20after%20changes.%20This%20should%20resolve%20the%20issue%20in%20most%20cases.)&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/6391)
Author
Owner

@rovertrack commented on GitHub (Nov 28, 2025):

its always gonna be pascal case but they can be different names!

@rovertrack commented on GitHub (Nov 28, 2025): its always gonna be pascal case but they can be different names!
Author
Owner

@dosubot[bot] commented on GitHub (Feb 27, 2026):

Hi, @TheMightyDev. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that overriding the default account.modelName to PascalCase in the config doesn't work, causing Prisma to query the lowercase account table and resulting in errors.
  • The root cause was identified as a mismatch between the Prisma model name and the Better Auth config modelName.
  • Both names must be identical and case-sensitive (e.g., Account) to avoid issues.
  • I recommended verifying Prisma migrations, ensuring table names match the override, and regenerating the Prisma client after schema changes.
  • The issue has been resolved by following these steps.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of better-auth by commenting below.
  • If no further updates are provided, I will automatically close this issue in 7 days.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Feb 27, 2026): Hi, @TheMightyDev. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that overriding the default `account.modelName` to PascalCase in the config doesn't work, causing Prisma to query the lowercase `account` table and resulting in errors. - The root cause was identified as a mismatch between the Prisma model name and the Better Auth config `modelName`. - Both names must be identical and case-sensitive (e.g., `Account`) to avoid issues. - I recommended verifying Prisma migrations, ensuring table names match the override, and regenerating the Prisma client after schema changes. - The issue has been resolved by following these steps. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of better-auth by commenting below. - If no further updates are provided, I will automatically close this issue in 7 days. Thanks for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2415