generate CLI outputs text(...) for foreign keys, causing MySQL foreign key errors (Drizzle and mysql) #1177

Closed
opened 2026-03-13 08:26:38 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @Andresuito on GitHub (May 7, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I'm using the npx @better-auth/cli generate command to scaffold my authentication schema, and I noticed that the CLI generates text("..._id") for foreign key columns such as userId, organizationId, etc.

This causes a MySQL error when trying to apply foreign key constraints:

BLOB, TEXT, GEOMETRY or JSON column can't be used in key specification

This is because in MySQL, TEXT columns cannot be used in foreign key constraints or indexed fields unless a length is explicitly defined.

Current vs. Expected behavior

  1. npx @better-auth/cli generate
  2. bun db:generate (To generate the schema)
  3. bun db:push (To upload to the DB)

What version of Better Auth are you using?

1.2.7

Provide environment information

- OS: Mac
- Browser: Arc

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

Package

Auth config (if applicable)

export const auth = betterAuth({
  appName: "Anticommon Dashboard",
  database: drizzleAdapter(db, {
    provider: "mysql",
  }),
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: false,
    autoSignIn: true,
    minPasswordLength: 8,
    maxPasswordLength: 20,
  },
  session: {
    expiresIn: 60 * 60 * 24 * 7,
    updateAge: 60 * 60 * 24,
  },
  plugins: [
    admin({
      defaultRole: "user",
    }),
    organization(),
    nextCookies(),
  ],
});

Additional context

No response

Originally created by @Andresuito on GitHub (May 7, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I'm using the npx @better-auth/cli generate command to scaffold my authentication schema, and I noticed that the CLI generates text("..._id") for foreign key columns such as userId, organizationId, etc. This causes a MySQL error when trying to apply foreign key constraints: BLOB, TEXT, GEOMETRY or JSON column can't be used in key specification This is because in MySQL, TEXT columns cannot be used in foreign key constraints or indexed fields unless a length is explicitly defined. ### Current vs. Expected behavior 1. npx @better-auth/cli generate 2. bun db:generate (To generate the schema) 3. bun db:push (To upload to the DB) ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - OS: Mac - Browser: Arc ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript export const auth = betterAuth({ appName: "Anticommon Dashboard", database: drizzleAdapter(db, { provider: "mysql", }), emailAndPassword: { enabled: true, requireEmailVerification: false, autoSignIn: true, minPasswordLength: 8, maxPasswordLength: 20, }, session: { expiresIn: 60 * 60 * 24 * 7, updateAge: 60 * 60 * 24, }, plugins: [ admin({ defaultRole: "user", }), organization(), nextCookies(), ], }); ``` ### Additional context _No response_
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1177