Error with Drizzle adapter after better-auth version update: The field does not exist in the schema. #2142

Closed
opened 2026-03-13 09:30:00 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @staguer on GitHub (Oct 17, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Configure betterAuth on the server with

    additionalFields: {
      isTest: { type: "boolean", defaultValue: false, input: false, fieldName: "is_test" },
      isBot: { type: "boolean", defaultValue: false, input: false, fieldName: "is_bot" },
      deletedAt: { type: "date", defaultValue: null, input: false, fieldName: "deleted_at" },
    },
  plugins: [
    anonymous({...})
  ]

and set the better-auth dependency in package.json to at least 1.3.8

Run a server and call await authClient.signIn.anonymous() on the client.

Current vs. Expected behavior

In 1.3.7 the field works fine. Users are able to sign in anonymously.
In 1.3.8 anon sign in fails with ERROR [Better Auth]: The field "is_test" does not exist in the "users" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate".

What version of Better Auth are you using?

1.3.8

System info

$pnpm dlx @better-auth/cli info --json
{
  "system": {
    "platform": "linux",
    "arch": "arm64",
    "version": "#1 SMP PREEMPT Tue Sep 30 00:46:49 UTC 2025",
    "release": "6.15.11-orbstack-00542-g4f455d264886",
    "cpuCount": 10,
    "cpuModel": "unknown",
    "totalMemory": "15.66 GB",
    "freeMemory": "9.80 GB"
  },
  "node": {
    "version": "v22.18.0",
    "env": "development"
  },
  "packageManager": {
    "name": "pnpm",
    "version": "10.15.0"
  },
  "frameworks": [
    {
      "name": "hono",
      "version": "^4.9.12"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "drizzle",
      "version": "^0.44.6"
    }
  ],
  "betterAuth": {
    "version": "=1.3.8",
    "config": {
      "appName": "Multi-chat",
      "baseURL": "http://localhost:3000/",
      "trustedOrigins": [
        "http://localhost:3000/",
        "https://localhost:3000/"
      ],
      "databaseHooks": {
        "user": {
          "create": {}
        }
      },
      "socialProviders": {
        "google": {
          "clientId": "[REDACTED]",
          "clientSecret": "[REDACTED]"
        }
      },
      "onAPIError": {
        "errorURL": "/account?error=api"
      },
      "plugins": [
        {
          "name": "anonymous",
          "config": {
            "id": "anonymous",
            "endpoints": {},
            "hooks": {
              "after": [
                {}
              ]
            },
            "schema": {
              "user": {
                "fields": {
                  "isAnonymous": {
                    "type": "boolean",
                    "required": false
                  }
                }
              }
            },
            "$ERROR_CODES": {
              "FAILED_TO_CREATE_USER": "Failed to create user",
              "COULD_NOT_CREATE_SESSION": "Could not create session",
              "ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY": "Anonymous users cannot sign in again anonymously"
            }
          }
        }
      ],
      "session": {
        "cookieCache": {
          "enabled": true
        }
      },
      "user": {
        "additionalFields": {
          "isTest": {
            "type": "boolean",
            "defaultValue": false,
            "input": false,
            "fieldName": "is_test"
          },
          "isBot": {
            "type": "boolean",
            "defaultValue": false,
            "input": false,
            "fieldName": "is_bot"
          },
          "deletedAt": {
            "type": "date",
            "defaultValue": null,
            "input": false,
            "fieldName": "deleted_at"
          }
        },
        "deleteUser": {
          "enabled": true
        }
      }
    }
  }
}

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

Backend

Auth config (if applicable)

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

Additional context

I tested current version 1.3.27 and the error is present there as well.

@better-auth/cli generate still does respect the fieldName property in version 1.3.23 but that also stops working in 1.3.24. Not sure if that fits under this issue or needs to be tracked separately.

Originally created by @staguer on GitHub (Oct 17, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Configure betterAuth on the server with ```TypeScript user: { additionalFields: { isTest: { type: "boolean", defaultValue: false, input: false, fieldName: "is_test" }, isBot: { type: "boolean", defaultValue: false, input: false, fieldName: "is_bot" }, deletedAt: { type: "date", defaultValue: null, input: false, fieldName: "deleted_at" }, }, plugins: [ anonymous({...}) ] ``` and set the better-auth dependency in package.json to at least 1.3.8 Run a server and call `await authClient.signIn.anonymous()` on the client. ### Current vs. Expected behavior In 1.3.7 the field works fine. Users are able to sign in anonymously. In 1.3.8 anon sign in fails with `ERROR [Better Auth]: The field "is_test" does not exist in the "users" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate".` ### What version of Better Auth are you using? 1.3.8 ### System info ```bash $pnpm dlx @better-auth/cli info --json { "system": { "platform": "linux", "arch": "arm64", "version": "#1 SMP PREEMPT Tue Sep 30 00:46:49 UTC 2025", "release": "6.15.11-orbstack-00542-g4f455d264886", "cpuCount": 10, "cpuModel": "unknown", "totalMemory": "15.66 GB", "freeMemory": "9.80 GB" }, "node": { "version": "v22.18.0", "env": "development" }, "packageManager": { "name": "pnpm", "version": "10.15.0" }, "frameworks": [ { "name": "hono", "version": "^4.9.12" } ], "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "drizzle", "version": "^0.44.6" } ], "betterAuth": { "version": "=1.3.8", "config": { "appName": "Multi-chat", "baseURL": "http://localhost:3000/", "trustedOrigins": [ "http://localhost:3000/", "https://localhost:3000/" ], "databaseHooks": { "user": { "create": {} } }, "socialProviders": { "google": { "clientId": "[REDACTED]", "clientSecret": "[REDACTED]" } }, "onAPIError": { "errorURL": "/account?error=api" }, "plugins": [ { "name": "anonymous", "config": { "id": "anonymous", "endpoints": {}, "hooks": { "after": [ {} ] }, "schema": { "user": { "fields": { "isAnonymous": { "type": "boolean", "required": false } } } }, "$ERROR_CODES": { "FAILED_TO_CREATE_USER": "Failed to create user", "COULD_NOT_CREATE_SESSION": "Could not create session", "ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY": "Anonymous users cannot sign in again anonymously" } } } ], "session": { "cookieCache": { "enabled": true } }, "user": { "additionalFields": { "isTest": { "type": "boolean", "defaultValue": false, "input": false, "fieldName": "is_test" }, "isBot": { "type": "boolean", "defaultValue": false, "input": false, "fieldName": "is_bot" }, "deletedAt": { "type": "date", "defaultValue": null, "input": false, "fieldName": "deleted_at" } }, "deleteUser": { "enabled": true } } } } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context I tested current version 1.3.27 and the error is present there as well. `@better-auth/cli generate` still does respect the fieldName property in version 1.3.23 but that also stops working in 1.3.24. Not sure if that fits under this issue or needs to be tracked separately.
GiteaMirror added the bug label 2026-03-13 09:30:00 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 17, 2025):

This error is caused by a breaking change in how Better Auth's Drizzle adapter and CLI handle custom user fields with the fieldName property. Starting from version 1.3.24, the Drizzle adapter no longer supports mapping logical field names to physical database column names using fieldName in additionalFields. Instead, Better Auth expects the logical field name (e.g., isTest) to match the property name in your Drizzle schema, not the database column name (e.g., is_test). Specifying fieldName now causes a "field does not exist" error, even if the column exists in your database. This change persists in all later versions, including 1.3.8 and 1.3.27 [thread].

Workaround:
Remove the fieldName property from your additionalFields config and ensure your Drizzle schema uses the same property names as your Better Auth config (e.g., isTest, isBot, deletedAt). The Drizzle schema can still map these properties to snake_case columns internally, but Better Auth will only recognize the logical property names.

If you need custom column mapping, this is not currently supported for Drizzle in Better Auth. You may want to follow future updates or request feature support for this capability [thread].

This issue is specific to the Drizzle adapter; Prisma and other adapters may handle fieldName differently [PR #3021].

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Oct 17, 2025): <!-- Answer --> This error is caused by a breaking change in how Better Auth's Drizzle adapter and CLI handle custom user fields with the `fieldName` property. Starting from version 1.3.24, the Drizzle adapter no longer supports mapping logical field names to physical database column names using `fieldName` in `additionalFields`. Instead, Better Auth expects the logical field name (e.g., `isTest`) to match the property name in your Drizzle schema, not the database column name (e.g., `is_test`). Specifying `fieldName` now causes a "field does not exist" error, even if the column exists in your database. This change persists in all later versions, including 1.3.8 and 1.3.27 [[thread](https://github.com/better-auth/better-auth/issues/4211#issuecomment-3413304976)]. **Workaround:** Remove the `fieldName` property from your `additionalFields` config and ensure your Drizzle schema uses the same property names as your Better Auth config (e.g., `isTest`, `isBot`, `deletedAt`). The Drizzle schema can still map these properties to snake_case columns internally, but Better Auth will only recognize the logical property names. If you need custom column mapping, this is not currently supported for Drizzle in Better Auth. You may want to follow future updates or request feature support for this capability [[thread](https://github.com/better-auth/better-auth/issues/4211#issuecomment-3413304976)]. This issue is specific to the Drizzle adapter; Prisma and other adapters may handle `fieldName` differently [[PR #3021](https://github.com/better-auth/better-auth/pull/3021)]. <!-- 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/4662e78d-9b02-4aa4-99ed-26f728ea4513?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/4662e78d-9b02-4aa4-99ed-26f728ea4513?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/4662e78d-9b02-4aa4-99ed-26f728ea4513?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/4662e78d-9b02-4aa4-99ed-26f728ea4513?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4662e78d-9b02-4aa4-99ed-26f728ea4513?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/4662e78d-9b02-4aa4-99ed-26f728ea4513?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4662e78d-9b02-4aa4-99ed-26f728ea4513?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&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/5386)
Author
Owner

@ping-maxwell commented on GitHub (Oct 19, 2025):

@staguer can I see your drizzle schema?

@ping-maxwell commented on GitHub (Oct 19, 2025): @staguer can I see your drizzle schema?
Author
Owner

@staguer commented on GitHub (Oct 20, 2025):

Yes, here:

auth-schema.generated.ts

Does this help?

@staguer commented on GitHub (Oct 20, 2025): Yes, here: [auth-schema.generated.ts](https://github.com/user-attachments/files/23007022/auth-schema.generated.ts) Does this help?
Author
Owner

@ping-maxwell commented on GitHub (Oct 22, 2025):

Remove the fieldname definitions:

Image
@ping-maxwell commented on GitHub (Oct 22, 2025): Remove the `fieldname` definitions: <img width="740" height="173" alt="Image" src="https://github.com/user-attachments/assets/9c63dcd3-652e-4334-af00-973097d05b2a" />
Author
Owner

@ping-maxwell commented on GitHub (Oct 22, 2025):

right now in your drizzle schema, you've defined those fields under isTest, isBot, etc. The lowercase with underscores are the names for your DB (not drizzle), which is why BA is breaking.

@ping-maxwell commented on GitHub (Oct 22, 2025): right now in your drizzle schema, you've defined those fields under `isTest`, `isBot`, etc. The lowercase with underscores are the names for your DB (not drizzle), which is why BA is breaking.
Author
Owner

@ping-maxwell commented on GitHub (Oct 23, 2025):

I'm going to close this for now as solved, please let me know if I got the wrong idea and you're still facing this issue! Happy to re-open.

@ping-maxwell commented on GitHub (Oct 23, 2025): I'm going to close this for now as solved, please let me know if I got the wrong idea and you're still facing this issue! Happy to re-open.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2142