[GH-ISSUE #8592] Foreign keys have incorrect type when using numeric IDs #11129

Closed
opened 2026-04-13 07:29:57 -05:00 by GiteaMirror · 3 comments
Owner

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

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Setup numeric IDs in the database config
  2. Use the generate CLI to update the schema

Current vs. Expected behavior

Currently all the foreign keys (userId e.g.) remain of type string after generating the schema. That makes sense for the default UUID approach, but when using numeric IDs I would expect the foreign keys to change their type to integer.

What version of Better Auth are you using?

1.4.10

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.14 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.6.2"
    }
  ],
  "betterAuth": {
    "version": "^1.5.5",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  trustedOrigins: [
    "http://localhost:3000",
  ],
  emailAndPassword: {
    enabled: true,
  },
  database: strapiAdapter(),
  advanced: {
    database: {
      generateId: "serial",
    },
  },
});

Additional context

No response

Originally created by @boazpoolman on GitHub (Mar 13, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8592 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. [Setup numeric IDs in the database config](https://better-auth.com/docs/concepts/database#numeric-ids) 2. Use the `generate` CLI to update the schema ### Current vs. Expected behavior Currently all the foreign keys (`userId` e.g.) remain of type `string` after generating the schema. That makes sense for the default UUID approach, but when using numeric IDs I would expect the foreign keys to change their type to `integer`. ### What version of Better Auth are you using? 1.4.10 ### 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.14 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.6.2" } ], "betterAuth": { "version": "^1.5.5", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ trustedOrigins: [ "http://localhost:3000", ], emailAndPassword: { enabled: true, }, database: strapiAdapter(), advanced: { database: { generateId: "serial", }, }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 07:29:57 -05:00
Author
Owner

@luchersou commented on GitHub (Mar 14, 2026):

Hey, I looked into this and wanted to share some findings to save others time.

After digging into the built-in generators (packages/cli/src/generators/drizzle.ts and prisma.ts), the foreign key type handling for generateId: "serial" is already working correctly for all built-in plugins.

For example, in drizzle.ts (line 66–78), there's already a check:

if (field.references?.field === "id") {
  const useNumberId = options.advanced?.database?.generateId === "serial";
  if (useNumberId) {
    // returns integer / int depending on dialect ✅
  }
}

The existing snapshots (auth-schema-number-id.txt, auth-schema-sqlite-number-id.txt, auth-schema-mysql-number-id.txt) confirm that userId, accountId, teamId and other FK fields are already generated as integer when using generateId: "serial" with the built-in Drizzle and Prisma generators. This also appears to cover the case reported in #3800 (column type mismatch for teamId in the organization plugin).

The issue in this report appears to be specific to strapiAdapter, which is a third-party adapter. When the CLI detects a custom adapter with a createSchema method, it delegates schema generation entirely to that adapter — bypassing the built-in generators entirely. The strapiAdapter's own createSchema implementation would need to handle generateId: "serial" independently.

If you're hitting this with a built-in adapter (Drizzle/Prisma/Kysely), could you share the exact CLI command you're running and the adapter config? That would help narrow down whether there's still a reproducible case in the core generators.

<!-- gh-comment-id:4061093645 --> @luchersou commented on GitHub (Mar 14, 2026): Hey, I looked into this and wanted to share some findings to save others time. After digging into the built-in generators (`packages/cli/src/generators/drizzle.ts` and `prisma.ts`), the foreign key type handling for `generateId: "serial"` is already working correctly for all built-in plugins. For example, in `drizzle.ts` (line 66–78), there's already a check: ```ts if (field.references?.field === "id") { const useNumberId = options.advanced?.database?.generateId === "serial"; if (useNumberId) { // returns integer / int depending on dialect ✅ } } ``` The existing snapshots (`auth-schema-number-id.txt`, `auth-schema-sqlite-number-id.txt`, `auth-schema-mysql-number-id.txt`) confirm that `userId`, `accountId`, `teamId` and other FK fields are already generated as `integer` when using `generateId: "serial"` with the built-in Drizzle and Prisma generators. This also appears to cover the case reported in #3800 (column type mismatch for `teamId` in the organization plugin). The issue in this report appears to be specific to `strapiAdapter`, which is a third-party adapter. When the CLI detects a custom adapter with a `createSchema` method, it delegates schema generation entirely to that adapter — bypassing the built-in generators entirely. The `strapiAdapter`'s own `createSchema` implementation would need to handle `generateId: "serial"` independently. If you're hitting this with a built-in adapter (Drizzle/Prisma/Kysely), could you share the exact CLI command you're running and the adapter config? That would help narrow down whether there's still a reproducible case in the core generators.
Author
Owner

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

That makes sense @luchersou.

I will just implement this as part of the Strapi adapter.

<!-- gh-comment-id:4096539935 --> @boazpoolman commented on GitHub (Mar 20, 2026): That makes sense @luchersou. I will just implement this as part of the Strapi adapter.
Author
Owner

@github-actions[bot] commented on GitHub (Mar 31, 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:4165912611 --> @github-actions[bot] commented on GitHub (Mar 31, 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#11129