[GH-ISSUE #8743] Renaming fields does not reflect in the schema #11179

Closed
opened 2026-04-13 07:32:15 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @boazpoolman on GitHub (Mar 23, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8743

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Setup better auth
  2. Create a database adapter with createSchema that logs the tables:
createSchema: async ({ tables }) => {
  console.log(tables);
},
  1. Update your better auth config to overwrite one of the core user fields:
import { betterAuth } from "better-auth";

const auth = () =>
  betterAuth({
    trustedOrigins: ["http://localhost:3000"],
    user: {
      fields: {
        email: "email_address"
      }
    }
  });

export default auth;

  1. Run npx auth generate to trigger the createSchema function
  2. See that the email field is not rewritten in the tables:
{
  user: {
    modelName: 'user',
    fields: {
      name: [Object],
      email: [Object],
      emailVerified: [Object],
      image: [Object],
      createdAt: [Object],
      updatedAt: [Object]
    },
    order: 1
  },
  session: {
    modelName: 'session',
    fields: {
      expiresAt: [Object],
      token: [Object],
      createdAt: [Object],
      updatedAt: [Object],
      ipAddress: [Object],
      userAgent: [Object],
      userId: [Object]
    },
    order: 2
  },
  account: {
    modelName: 'account',
    fields: {
      accountId: [Object],
      providerId: [Object],
      userId: [Object],
      accessToken: [Object],
      refreshToken: [Object],
      idToken: [Object],
      accessTokenExpiresAt: [Object],
      refreshTokenExpiresAt: [Object],
      scope: [Object],
      password: [Object],
      createdAt: [Object],
      updatedAt: [Object]
    },
    order: 3
  },
  verification: {
    modelName: 'verification',
    fields: {
      identifier: [Object],
      value: [Object],
      expiresAt: [Object],
      createdAt: [Object],
      updatedAt: [Object]
    },
    order: 4
  }
}

Current vs. Expected behavior

I would expect the field name change to be reflected in the tables so that I can correctly create the updated schema for my database adapter.

On a side note, I noticed that if I manually use getSchema, I do get the appropriate tables.

import { getAuthTables, getSchema } from "better-auth/db";

// Does not contain the field rename
const authTables = getAuthTables(opts);

// Does contain the field rename
const schema = getSchema(opts);

What version of Better Auth are you using?

1.5.6

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:21 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6000",
    "release": "24.6.0",
    "cpuCount": 8,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.13 GB"
  },
  "node": {
    "version": "v22.19.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.3"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "^18.0.0"
    }
  ],
  "databases": [
    {
      "name": "better-sqlite3",
      "version": "12.4.1"
    }
  ],
  "betterAuth": {
    "version": "catalog:better-auth",
    "config": null
  }
}

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

Package

Auth config (if applicable)


Additional context

No response

Originally created by @boazpoolman on GitHub (Mar 23, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8743 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Setup better auth 2. Create a database adapter with `createSchema` that logs the tables: ``` createSchema: async ({ tables }) => { console.log(tables); }, ``` 3. Update your better auth config to overwrite one of the core user fields: ``` import { betterAuth } from "better-auth"; const auth = () => betterAuth({ trustedOrigins: ["http://localhost:3000"], user: { fields: { email: "email_address" } } }); export default auth; ``` 4. Run `npx auth generate` to trigger the `createSchema` function 5. See that the email field is not rewritten in the tables: ``` { user: { modelName: 'user', fields: { name: [Object], email: [Object], emailVerified: [Object], image: [Object], createdAt: [Object], updatedAt: [Object] }, order: 1 }, session: { modelName: 'session', fields: { expiresAt: [Object], token: [Object], createdAt: [Object], updatedAt: [Object], ipAddress: [Object], userAgent: [Object], userId: [Object] }, order: 2 }, account: { modelName: 'account', fields: { accountId: [Object], providerId: [Object], userId: [Object], accessToken: [Object], refreshToken: [Object], idToken: [Object], accessTokenExpiresAt: [Object], refreshTokenExpiresAt: [Object], scope: [Object], password: [Object], createdAt: [Object], updatedAt: [Object] }, order: 3 }, verification: { modelName: 'verification', fields: { identifier: [Object], value: [Object], expiresAt: [Object], createdAt: [Object], updatedAt: [Object] }, order: 4 } } ``` ### Current vs. Expected behavior I would expect the field name change to be reflected in the tables so that I can correctly create the updated schema for my database adapter. On a side note, I noticed that if I manually use `getSchema`, I do get the appropriate tables. ``` import { getAuthTables, getSchema } from "better-auth/db"; // Does not contain the field rename const authTables = getAuthTables(opts); // Does contain the field rename const schema = getSchema(opts); ``` ### What version of Better Auth are you using? 1.5.6 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:21 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6000", "release": "24.6.0", "cpuCount": 8, "cpuModel": "Apple M1 Pro", "totalMemory": "16.00 GB", "freeMemory": "0.13 GB" }, "node": { "version": "v22.19.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.3" }, "frameworks": [ { "name": "react", "version": "^18.0.0" } ], "databases": [ { "name": "better-sqlite3", "version": "12.4.1" } ], "betterAuth": { "version": "catalog:better-auth", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 07:32:15 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 23, 2026):

This looks like a confirmed issue. The createSchema callback receives tables from getAuthTables, which keeps logical field names as keys (e.g., email) and stores the actual database column name in the fieldName property instead.

You're right that getSchema transforms the output correctly by swapping keys to actual column names.

Workaround: In your createSchema callback, read field.fieldName to get the actual database column name rather than relying on the object key:

createSchema: async ({ tables }) => {
  for (const [tableName, table] of Object.entries(tables)) {
    for (const [logicalName, field] of Object.entries(table.fields)) {
      const actualColumnName = field.fieldName; // "email_address" instead of "email"
      // Use actualColumnName when creating your schema
    }
  }
}

There are several related field mapping issues tracked: #2899, #4564, #4408, #5649.

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:4110101341 --> @dosubot[bot] commented on GitHub (Mar 23, 2026): <!-- Answer --> This looks like a confirmed issue. The `createSchema` callback receives tables from [`getAuthTables`](https://github.com/better-auth/better-auth/blob/03278b5ad62c4cea61a8373bb7fe522519b31a42/packages/core/src/db/adapter/factory.ts#L1357-L1371), which keeps logical field names as keys (e.g., `email`) and stores the actual database column name in the `fieldName` property instead. You're right that [`getSchema`](https://github.com/better-auth/better-auth/blob/03278b5ad62c4cea61a8373bb7fe522519b31a42/packages/better-auth/src/db/get-schema.ts#L19) transforms the output correctly by swapping keys to actual column names. **Workaround**: In your `createSchema` callback, read `field.fieldName` to get the actual database column name rather than relying on the object key: ```typescript createSchema: async ({ tables }) => { for (const [tableName, table] of Object.entries(tables)) { for (const [logicalName, field] of Object.entries(table.fields)) { const actualColumnName = field.fieldName; // "email_address" instead of "email" // Use actualColumnName when creating your schema } } } ``` There are several related field mapping issues tracked: [#2899](https://github.com/better-auth/better-auth/issues/2899), [#4564](https://github.com/better-auth/better-auth/issues/4564), [#4408](https://github.com/better-auth/better-auth/issues/4408), [#5649](https://github.com/better-auth/better-auth/issues/5649). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/96540de9-83a2-44b6-917d-1bdad347d654?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/96540de9-83a2-44b6-917d-1bdad347d654?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/96540de9-83a2-44b6-917d-1bdad347d654?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/96540de9-83a2-44b6-917d-1bdad347d654?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/96540de9-83a2-44b6-917d-1bdad347d654?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/96540de9-83a2-44b6-917d-1bdad347d654?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/96540de9-83a2-44b6-917d-1bdad347d654?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-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&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20looks%20like%20a%20confirmed%20issue.%20The%20%60createSchema%60%20callback%20receives%20tables%20from%20%5B%60getAuthTables%60%5D%28https%3A//github.com/better-auth/better-auth/blob/03278b5ad62c4cea61a8373bb7fe522519b31a42/packages/core/src/db/adapter/factory.ts%23L1357-L1371%29%2C%20which%20keeps%20logical%20field%20names%20as%20keys%20%28e.g.%2C%20%60email%60%29%20and%20stores%20the%20actual%20database%20column%20name%20in%20the%20%60fieldName%60%20property%20instead.%0A%0AYou%27re%20right%20that%20%5B%60getSchema%60%5D%28https%3A//github.com/better-auth/better-auth/blob/03278b5ad62c4cea61a8373bb7fe522519b31a42/packages/better-auth/src/db/get-schema.ts%23L19%29%20transforms%20the%20output%20correctly%20by%20swapping%20keys%20to%20actual%20column%20names.%0A%0A%2A%2AWorkaround%2A%2A%3A%20In%20your%20%60createSchema%60%20callback%2C%20read%20%60field.fieldName%60%20to%20get%20the%20actual%20database%20column%20name%20rather%20than%20relying%20on%20the%20object%20key%3A%0A%0A%60%60%60typescript%0AcreateSchema%3A%20async%20%28%7B%20tables%20%7D%29%20%3D%3E%20%7B%0A%20%20for%20%28const%20%5BtableName%2C%20table%5D%20of%20Object.entries%28tables%29%29%20%7B%0A%20%20%20%20for%20%28const%20%5BlogicalName%2C%20field%5D%20of%20Object.entries%28table.fields%29%29%20%7B%0A%20%20%20%20%20%20const%20actualColumnName%20%3D%20field.fieldName%3B%20//%20%22email_address%22%20instead%20of%20%22email%22%0A%20%20%20%20%20%20//%20Use%20actualColumnName%20when%20creating%20your%20schema%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A%60%60%60%0A%0AThere%20are%20several%20related%20field%20mapping%20issues%20tracked%3A%20%5B%232899%5D%28https%3A//github.com/better-auth/better-auth/issues/2899%29%2C%20%5B%234564%5D%28https%3A//github.com/better-auth/better-auth/issues/4564%29%2C%20%5B%234408%5D%28https%3A//github.com/better-auth/better-auth/issues/4408%29%2C%20%5B%235649%5D%28https%3A//github.com/better-auth/better-auth/issues/5649%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&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/8743)
Author
Owner

@boazpoolman commented on GitHub (Mar 23, 2026):

OK, that makes sense @dosubot. It can be implemented like you mentioned. Closing.

<!-- gh-comment-id:4110166586 --> @boazpoolman commented on GitHub (Mar 23, 2026): OK, that makes sense @dosubot. It can be implemented like you mentioned. Closing.
Author
Owner

@dosubot[bot] commented on GitHub (Mar 23, 2026):

Glad that helped! The field.fieldName approach should work well for your custom adapter. Feel free to reopen if you run into any issues with the implementation. 👍

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:4110168255 --> @dosubot[bot] commented on GitHub (Mar 23, 2026): <!-- Answer --> Glad that helped! The `field.fieldName` approach should work well for your custom adapter. Feel free to reopen if you run into any issues with the implementation. 👍 <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/63847030-0f59-498c-867d-dc1a65823607?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/63847030-0f59-498c-867d-dc1a65823607?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/63847030-0f59-498c-867d-dc1a65823607?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/63847030-0f59-498c-867d-dc1a65823607?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/63847030-0f59-498c-867d-dc1a65823607?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/63847030-0f59-498c-867d-dc1a65823607?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/63847030-0f59-498c-867d-dc1a65823607?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-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&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Glad%20that%20helped%21%20The%20%60field.fieldName%60%20approach%20should%20work%20well%20for%20your%20custom%20adapter.%20Feel%20free%20to%20reopen%20if%20you%20run%20into%20any%20issues%20with%20the%20implementation.%20%F0%9F%91%8D)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&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/8743)
Author
Owner

@iamharidasan commented on GitHub (Mar 25, 2026):

Will this be fixed in next release?

<!-- gh-comment-id:4125777726 --> @iamharidasan commented on GitHub (Mar 25, 2026): Will this be fixed in next release?
Author
Owner

@boazpoolman commented on GitHub (Mar 25, 2026):

This turned out to be a non issue, see Dosubots comment https://github.com/better-auth/better-auth/issues/8743#issuecomment-4110101341

<!-- gh-comment-id:4125920191 --> @boazpoolman commented on GitHub (Mar 25, 2026): This turned out to be a non issue, see Dosubots comment https://github.com/better-auth/better-auth/issues/8743#issuecomment-4110101341
Author
Owner

@github-actions[bot] commented on GitHub (Apr 2, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4173719028 --> @github-actions[bot] commented on GitHub (Apr 2, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11179