[GH-ISSUE #1873] A problem while creating additional fields, uuid type not string #8955

Closed
opened 2026-04-13 04:12:15 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @tarekkabritco on GitHub (Mar 19, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1873

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I want to create an additional field and link it with another tablet

Current vs. Expected behavior

alter table "customers" add column "site_id" text references "sites" ("id");
the schema generates this but it throws this error when migration
detail: 'Key columns "site_id" and "id" are of incompatible types: text and uuid.',
the site_id is uuid typed

What version of Better Auth are you using?

1.2.4

Provide environment information

- Db: [supabase]

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

Types

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { Pool } from "pg";
import { anonymous } from "better-auth/plugins";
import { nextCookies } from "better-auth/next-js";

export const auth = betterAuth({
  database: new Pool({
    connectionString: process.env.DATABASE_URL!
  }),
  secret: process.env.BETTER_AUTH_SECRET,
  emailAndPassword: {
    enabled: true,
  },
  user: {
    changeEmail: {
      enabled: true,
    },
    modelName: "customers",
    additionalFields: {
      site_id: {
        type: "uuid", => here
        required: false,
        references: {
          model: "sites",
          onDelete: "cascade",
          field: "id",
        },
      }
    }
  },
  plugins: [anonymous(), nextCookies()]
})

export type Session = typeof auth.$Infer.Session

Additional context

No response

Originally created by @tarekkabritco on GitHub (Mar 19, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1873 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I want to create an additional field and link it with another tablet ### Current vs. Expected behavior alter table "customers" add column "site_id" text references "sites" ("id"); the schema generates this but it throws this error when migration detail: 'Key columns "site_id" and "id" are of incompatible types: text and uuid.', the site_id is uuid typed ### What version of Better Auth are you using? 1.2.4 ### Provide environment information ```bash - Db: [supabase] ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { Pool } from "pg"; import { anonymous } from "better-auth/plugins"; import { nextCookies } from "better-auth/next-js"; export const auth = betterAuth({ database: new Pool({ connectionString: process.env.DATABASE_URL! }), secret: process.env.BETTER_AUTH_SECRET, emailAndPassword: { enabled: true, }, user: { changeEmail: { enabled: true, }, modelName: "customers", additionalFields: { site_id: { type: "uuid", => here required: false, references: { model: "sites", onDelete: "cascade", field: "id", }, } } }, plugins: [anonymous(), nextCookies()] }) export type Session = typeof auth.$Infer.Session ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 04:12:15 -05:00
Author
Owner

@Makakusnik commented on GitHub (Mar 19, 2025):

+1 Also, it would be nice if there was option for core schemas aswell.

<!-- gh-comment-id:2737217519 --> @Makakusnik commented on GitHub (Mar 19, 2025): +1 Also, it would be nice if there was option for core schemas aswell.
Author
Owner

@astanciu commented on GitHub (May 26, 2025):

This problem also shows up if you disable id generation and the database generates any type of id that is not text, for example UUIDs. The generated references are text type

create table "session" (
"id" text not null primary key,
"expiresAt" timestamp not null,
"token" text not null unique,
"createdAt" timestamp not null,
"updatedAt" timestamp not null,
"ipAddress" text,
"userAgent" text,
"userId" text not null references "users" ("id"));   <--- wrong, should be UUID
<!-- gh-comment-id:2910181762 --> @astanciu commented on GitHub (May 26, 2025): This problem also shows up if you disable id generation and the database generates any type of id that is not text, for example UUIDs. The generated references are text type ``` create table "session" ( "id" text not null primary key, "expiresAt" timestamp not null, "token" text not null unique, "createdAt" timestamp not null, "updatedAt" timestamp not null, "ipAddress" text, "userAgent" text, "userId" text not null references "users" ("id")); <--- wrong, should be UUID ```
Author
Owner

@dosubot[bot] commented on GitHub (Aug 25, 2025):

Hi, @tarekkabritco. 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 a migration error in Better Auth v1.2.4 where adding a "uuid" field referencing another table's "id" results in the schema using "text" instead of "uuid".
  • Other users confirmed the issue, especially when disabling ID generation and using non-text IDs like UUIDs.
  • The problem causes foreign key references to default to "text", leading to schema mismatches.
  • There is interest in an option to specify core schema types correctly to prevent this issue.
  • The issue remains unresolved with no current fix or workaround.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting below.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3220862401 --> @dosubot[bot] commented on GitHub (Aug 25, 2025): Hi, @tarekkabritco. 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 a migration error in Better Auth v1.2.4 where adding a "uuid" field referencing another table's "id" results in the schema using "text" instead of "uuid". - Other users confirmed the issue, especially when disabling ID generation and using non-text IDs like UUIDs. - The problem causes foreign key references to default to "text", leading to schema mismatches. - There is interest in an option to specify core schema types correctly to prevent this issue. - The issue remains unresolved with no current fix or workaround. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting below. - If I do not hear back within 7 days, I will automatically close this issue. Thank you 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#8955