[GH-ISSUE #2937] [SignIn with Username] (`Model ${model} does not exist in the database. #9403

Closed
opened 2026-04-13 04:50:51 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @jpainam on GitHub (Jun 7, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2937

Is this suited for github?

I have generated the Prisma client

  • Yes, this is suited for github

To Reproduce

https://github.com/better-auth/better-auth

Current vs. Expected behavior

I'm getting this error when creating a user. I have capitalized my model name and using prisma

Invalid `db[model].create()` invocation in
/.next/server/chunks/node_modules_better-auth_dist_e7fe42cb._.js:3251:44

  3248 if (!db[model]) {
  3249     throw new __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$better$2d$auth$2f$dist$2f$shared$2f$better$2d$auth$2e$DdzSJf$2d$n$2e$mjs__$5b$app$2d$route$5d$__$28$ecmascript$29$__["B"](`Model ${model} does not exist in the database. If you haven't generated the Prisma client, you need to run 'npx prisma generate'`);
  3250 }
 3251 return await db[model].create({
         data: {
           name: "John",
           email: "johndoe@gmail.com",
           emailVerified: false,
           createdAt: new Date("2025-06-07T00:44:50.648Z"),
           updatedAt: new Date("2025-06-07T00:44:50.648Z"),
           username: "john",
           displayUsername: "John",
       +   password: String
         },
         select: undefined
       })

Argument `password` is missing.] {
  clientVersion: '6.8.2'
}

What version of Better Auth are you using?

1.2.8

Provide environment information

Mac OS

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

Backend

Auth config (if applicable)

import type { BetterAuthOptions } from "better-auth";
import { expo } from "@better-auth/expo";
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";
import { apiKey, oAuthProxy, username } from "better-auth/plugins";


import { sendEmail } from "@repo/utils";

export function initAuth(options: {
  baseUrl: string;
  productionUrl: string;
  secret: string | undefined;
}) {
  const config = {
    database: prismaAdapter(db, {
      provider: "postgresql",
    }),
    user: {
      modelName: "User",
    },
    session: {
      modelName: "Session",
    },
    account: {
      modelName: "Account",
    },
    verification: {
      modelName: "Verification",
    },

    baseURL: options.baseUrl,
    secret: options.secret,
    emailAndPassword: {
      enabled: true,
      requireEmailVerification: true,
    },
    plugins: [
      username(),
      apiKey(),
      
      
      nextCookies(),
    ],
    
    trustedOrigins: ["expo://"],
  } satisfies BetterAuthOptions;

  return betterAuth(config);
}

export type Auth = ReturnType<typeof initAuth>;
export type Session = Auth["$Infer"]["Session"];

Additional context

No response

Originally created by @jpainam on GitHub (Jun 7, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2937 ### Is this suited for github? I have generated the Prisma client - [x] Yes, this is suited for github ### To Reproduce https://github.com/better-auth/better-auth ### Current vs. Expected behavior I'm getting this error when creating a user. I have capitalized my model name and using prisma ```tsx Invalid `db[model].create()` invocation in /.next/server/chunks/node_modules_better-auth_dist_e7fe42cb._.js:3251:44 3248 if (!db[model]) { 3249 throw new __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$better$2d$auth$2f$dist$2f$shared$2f$better$2d$auth$2e$DdzSJf$2d$n$2e$mjs__$5b$app$2d$route$5d$__$28$ecmascript$29$__["B"](`Model ${model} does not exist in the database. If you haven't generated the Prisma client, you need to run 'npx prisma generate'`); 3250 } → 3251 return await db[model].create({ data: { name: "John", email: "johndoe@gmail.com", emailVerified: false, createdAt: new Date("2025-06-07T00:44:50.648Z"), updatedAt: new Date("2025-06-07T00:44:50.648Z"), username: "john", displayUsername: "John", + password: String }, select: undefined }) Argument `password` is missing.] { clientVersion: '6.8.2' } ``` ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash Mac OS ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import type { BetterAuthOptions } from "better-auth"; import { expo } from "@better-auth/expo"; import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { nextCookies } from "better-auth/next-js"; import { apiKey, oAuthProxy, username } from "better-auth/plugins"; import { sendEmail } from "@repo/utils"; export function initAuth(options: { baseUrl: string; productionUrl: string; secret: string | undefined; }) { const config = { database: prismaAdapter(db, { provider: "postgresql", }), user: { modelName: "User", }, session: { modelName: "Session", }, account: { modelName: "Account", }, verification: { modelName: "Verification", }, baseURL: options.baseUrl, secret: options.secret, emailAndPassword: { enabled: true, requireEmailVerification: true, }, plugins: [ username(), apiKey(), nextCookies(), ], trustedOrigins: ["expo://"], } satisfies BetterAuthOptions; return betterAuth(config); } export type Auth = ReturnType<typeof initAuth>; export type Session = Auth["$Infer"]["Session"]; ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:50:51 -05:00
Author
Owner

@jpainam commented on GitHub (Jun 7, 2025):

Can you log the model name better-auth is unable to find ?

<!-- gh-comment-id:2951340781 --> @jpainam commented on GitHub (Jun 7, 2025): Can you log the `model name` better-auth is unable to find ?
Author
Owner

@Kinfe123 commented on GitHub (Jun 7, 2025):

can you please share me the schema.prisma file ?

<!-- gh-comment-id:2952005415 --> @Kinfe123 commented on GitHub (Jun 7, 2025): can you please share me the `schema.prisma` file ?
Author
Owner

@jpainam commented on GitHub (Jun 7, 2025):

I have many other fields in my user.prisma file. sharing some .

model User {
    id                           String                     @id @default(uuid())
    name                         String
    emailVerified                Boolean                    @default(false)
    image                        String?
    sessions                     Session[]
    accounts                     Account[]
    apikeys                      Apikey[]
    username                     String
    email                        String?
    avatar                       String?
    isActive                     Boolean                    @default(true)
    password                     String
    createdAt                    DateTime                   @default(now())
    updatedAt                    DateTime                   @updatedAt
    announcements                Announcement[]
    documents                    Document[]                 @relation("owner")
   

    @@unique([username])
}

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

    @@unique([token])
}

model Account {
    id                    String    @id
    accountId             String
    providerId            String
    userId                String
    user                  User      @relation(fields: [userId], references: [id], onDelete: Cascade)
    accessToken           String?
    refreshToken          String?
    idToken               String?
    accessTokenExpiresAt  DateTime?
    refreshTokenExpiresAt DateTime?
    scope                 String?
    password              String?
    createdAt             DateTime
    updatedAt             DateTime
}

model Verification {
    id         String    @id
    identifier String
    value      String
    expiresAt  DateTime
    createdAt  DateTime?
    updatedAt  DateTime?
}

model Apikey {
    id                  String    @id
    name                String?
    start               String?
    prefix              String?
    key                 String
    userId              String
    user                User      @relation(fields: [userId], references: [id], onDelete: Cascade)
    refillInterval      Int?
    refillAmount        Int?
    lastRefillAt        DateTime?
    enabled             Boolean?
    rateLimitEnabled    Boolean?
    rateLimitTimeWindow Int?
    rateLimitMax        Int?
    requestCount        Int?
    remaining           Int?
    lastRequest         DateTime?
    expiresAt           DateTime?
    createdAt           DateTime
    updatedAt           DateTime
    permissions         String?
    metadata            String?
}
<!-- gh-comment-id:2952062547 --> @jpainam commented on GitHub (Jun 7, 2025): I have many other fields in my `user.prisma` file. sharing some . ```ts model User { id String @id @default(uuid()) name String emailVerified Boolean @default(false) image String? sessions Session[] accounts Account[] apikeys Apikey[] username String email String? avatar String? isActive Boolean @default(true) password String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt announcements Announcement[] documents Document[] @relation("owner") @@unique([username]) } model Session { id String @id expiresAt DateTime token String createdAt DateTime updatedAt DateTime ipAddress String? userAgent String? userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@unique([token]) } model Account { id String @id accountId String providerId String userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) accessToken String? refreshToken String? idToken String? accessTokenExpiresAt DateTime? refreshTokenExpiresAt DateTime? scope String? password String? createdAt DateTime updatedAt DateTime } model Verification { id String @id identifier String value String expiresAt DateTime createdAt DateTime? updatedAt DateTime? } model Apikey { id String @id name String? start String? prefix String? key String userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) refillInterval Int? refillAmount Int? lastRefillAt DateTime? enabled Boolean? rateLimitEnabled Boolean? rateLimitTimeWindow Int? rateLimitMax Int? requestCount Int? remaining Int? lastRequest DateTime? expiresAt DateTime? createdAt DateTime updatedAt DateTime permissions String? metadata String? } ```
Author
Owner

@jpainam commented on GitHub (Jun 13, 2025):

had to change my model names to user, Prisma automically camelCases model names, so we should camelCase here

<!-- gh-comment-id:2969023680 --> @jpainam commented on GitHub (Jun 13, 2025): had to change my model names to `user`, Prisma automically camelCases model names, so we should camelCase here
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9403