[GH-ISSUE #2801] In Drizzle MySQL mode, wrong column types are generated #9354

Closed
opened 2026-04-13 04:47:36 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @hexwanderer on GitHub (May 27, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2801

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

When using the generate command in CLI for drizzle MySQL, the outputted schema object is subtly wrong.

Auth object:

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: "mysql",
        usePlural: true,
    }),
    secret: env.BETTER_AUTH_SECRET,
    emailAndPassword: {
        enabled: true,
    },
    plugins: [bearer()],
    trustedOrigins: [env.CLIENT],
});

Generated file is:

export const users = mysqlTable("users", {
    id: varchar("id", { length: 36 }).primaryKey(),
    ...
});

export const accounts = mysqlTable("accounts", {
        ...
    userId: text("user_id", )
        .notNull()
        .references(() => users.id, { onDelete: "cascade" }),
});

This causes the error when running drizzle-kit push:

Error: Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'accounts_user_id_users_id_fk' are incompatible.

I need to manually edit myself to:

export const sessions = mysqlTable("sessions", {
        ...
    userId: varchar("user_id", { length: 36 })
        .notNull()
        .references(() => users.id, { onDelete: "cascade" }),
});

Then the push works. I am using TiDB free tier if that's relevant.

Current vs. Expected behavior

Expected behavior would be for the CLI to generate varchar -> varchar references.

What version of Better Auth are you using?

1.2.8

Provide environment information

- OS: macOS 15.3.1

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

Backend

Auth config (if applicable)

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: "mysql",
        usePlural: true,
    }),
    secret: env.BETTER_AUTH_SECRET,
    emailAndPassword: {
        enabled: true,
    },
    plugins: [bearer()],
    trustedOrigins: [env.CLIENT],
});

Additional context

No response

Originally created by @hexwanderer on GitHub (May 27, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2801 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce When using the generate command in CLI for drizzle MySQL, the outputted schema object is subtly wrong. Auth object: ```ts export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "mysql", usePlural: true, }), secret: env.BETTER_AUTH_SECRET, emailAndPassword: { enabled: true, }, plugins: [bearer()], trustedOrigins: [env.CLIENT], }); ``` Generated file is: ```ts export const users = mysqlTable("users", { id: varchar("id", { length: 36 }).primaryKey(), ... }); export const accounts = mysqlTable("accounts", { ... userId: text("user_id", ) .notNull() .references(() => users.id, { onDelete: "cascade" }), }); ``` This causes the error when running drizzle-kit push: ```bash Error: Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'accounts_user_id_users_id_fk' are incompatible. ``` I need to manually edit myself to: ```ts export const sessions = mysqlTable("sessions", { ... userId: varchar("user_id", { length: 36 }) .notNull() .references(() => users.id, { onDelete: "cascade" }), }); ``` Then the push works. I am using TiDB free tier if that's relevant. ### Current vs. Expected behavior Expected behavior would be for the CLI to generate varchar -> varchar references. ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - OS: macOS 15.3.1 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "mysql", usePlural: true, }), secret: env.BETTER_AUTH_SECRET, emailAndPassword: { enabled: true, }, plugins: [bearer()], trustedOrigins: [env.CLIENT], }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:47:36 -05:00
Author
Owner

@Kinfe123 commented on GitHub (May 28, 2025):

Yeah this is more into the TiDB supporting foreign key constraints between the text and varchar. please refer here - https://docs.pingcap.com/tidb/stable/foreign-key/ but would look into something that can be make this easier.

<!-- gh-comment-id:2914566767 --> @Kinfe123 commented on GitHub (May 28, 2025): Yeah this is more into the TiDB supporting foreign key constraints between the text and varchar. please refer here - https://docs.pingcap.com/tidb/stable/foreign-key/ but would look into something that can be make this easier.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9354