APIKey Table schema generation is incorrect #1057

Closed
opened 2026-03-13 08:20:42 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @djt on GitHub (Apr 16, 2025).

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create backend
  2. Add apiKey plugin
  3. Add custom modelName for user table in config:
    export const auth = betterAuth({ ... user: { modelName: 'users' }, ... });
  4. npx @better-auth/cli generate

The reference for the user Id will reference the default table name of user.

userId: text('user_id').notNull().references(()=> user.id, { onDelete: 'cascade' }),

Current vs. Expected behavior

Current:
userId: text('user_id').notNull().references(()=> user.id, { onDelete: 'cascade' }),
Expected:
userId: text('user_id').notNull().references(()=> users.id, { onDelete: 'cascade' }),

What version of Better Auth are you using?

1.2.7

Provide environment information

- OS: Mac OSX
- Browser: Chrome

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  user: {  
    modelName: 'users'
  },
});

Additional context

No response

Originally created by @djt on GitHub (Apr 16, 2025). Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create backend 2. Add apiKey plugin 3. Add custom modelName for user table in config: ` export const auth = betterAuth({ ... user: { modelName: 'users' }, ... }); ` 4. npx @better-auth/cli generate The reference for the user Id will reference the default table name of user. ` userId: text('user_id').notNull().references(()=> user.id, { onDelete: 'cascade' }), ` ### Current vs. Expected behavior Current: ` userId: text('user_id').notNull().references(()=> user.id, { onDelete: 'cascade' }), ` Expected: ` userId: text('user_id').notNull().references(()=> users.id, { onDelete: 'cascade' }), ` ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - OS: Mac OSX - Browser: Chrome ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ user: { modelName: 'users' }, }); ``` ### Additional context _No response_
GiteaMirror added the adapterbug labels 2026-03-13 08:20:42 -05:00
Author
Owner

@ping-maxwell commented on GitHub (Apr 20, 2025):

@djt if you update to latest, do you still run into this issue?

@ping-maxwell commented on GitHub (Apr 20, 2025): @djt if you update to latest, do you still run into this issue?
Author
Owner

@johnrjj commented on GitHub (Apr 22, 2025):

Happening to me as well

@johnrjj commented on GitHub (Apr 22, 2025): Happening to me as well
Author
Owner

@ping-maxwell commented on GitHub (Aug 11, 2025):

What version are you on @johnrjj ?

@ping-maxwell commented on GitHub (Aug 11, 2025): What version are you on @johnrjj ?
Author
Owner

@bunday commented on GitHub (Aug 20, 2025):

What version are you on @johnrjj ?

@ping-maxwell Currently using version 1.3.7 and this issue persists

@bunday commented on GitHub (Aug 20, 2025): > What version are you on [@johnrjj](https://github.com/johnrjj) ? @ping-maxwell Currently using version `1.3.7` and this issue persists
Author
Owner

@ping-maxwell commented on GitHub (Aug 20, 2025):

@bunday Which adapter are you using? Drizzle?
The schema generation runs off our CLI, are you sure you're not using a cached/old version of our CLI?

@ping-maxwell commented on GitHub (Aug 20, 2025): @bunday Which adapter are you using? Drizzle? The schema generation runs off our CLI, are you sure you're not using a cached/old version of our CLI?
Author
Owner

@bunday commented on GitHub (Aug 20, 2025):

@ping-maxwell Currently using Drizzle adapter and the cli i have is this @better-auth/cli@1.3.7. Are you not able to reproduce this schema generation with the wrong table name reference?

@bunday commented on GitHub (Aug 20, 2025): @ping-maxwell Currently using Drizzle adapter and the cli i have is this `@better-auth/cli@1.3.7`. Are you not able to reproduce this schema generation with the wrong table name reference?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1057