Adding additional fields to users table throws an error when signing up #1176

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

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

Package Versions

  • better-auth:1.2.7
  • drizzle-orm:0.43.1

Schema

export const customers = pgTable("customers", {
    id: text('id').primaryKey(),
    name: text('name').notNull(),
    email: text('email').notNull().unique(),
    emailVerified: boolean('email_verified').notNull(),
    image: text('image'),
    createdAt: timestamp('created_at').notNull(),
    updatedAt: timestamp('updated_at').notNull(),
    businessId: text('business_id').notNull().references(() => businesses.id, { onDelete: 'cascade' })
    //👆 additional field
});

Config


export const auth = betterAuth({
... // other options
user: {
        modelName: "customers",
        additionalFields: {
            businessId: {
                type: 'string',
                fieldName: 'business_id',
                references: {
                    field: 'id',
                    model: 'businesses',
                    onDelete: 'cascade'
                },
                required: true,
                returned: true,
            },
        }
    },
})

Database

After generating schema with better-auth cli i pushed changes to database using drizzle.

Image

Problem

2025-05-07T15:02:33.991Z ERROR [Better Auth]: Failed to create user 1 | class BetterAuthError extends Error {
2 |   constructor(message, cause) {
3 |     super(message);
        ^
BetterAuthError: The field "business_id" does not exist in the "customers" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate".
 cause: undefined,
Originally created by @mfazail on GitHub (May 7, 2025). ### Package Versions - better-auth:1.2.7 - drizzle-orm:0.43.1 ### Schema ```ts export const customers = pgTable("customers", { id: text('id').primaryKey(), name: text('name').notNull(), email: text('email').notNull().unique(), emailVerified: boolean('email_verified').notNull(), image: text('image'), createdAt: timestamp('created_at').notNull(), updatedAt: timestamp('updated_at').notNull(), businessId: text('business_id').notNull().references(() => businesses.id, { onDelete: 'cascade' }) //👆 additional field }); ``` ### Config ```ts export const auth = betterAuth({ ... // other options user: { modelName: "customers", additionalFields: { businessId: { type: 'string', fieldName: 'business_id', references: { field: 'id', model: 'businesses', onDelete: 'cascade' }, required: true, returned: true, }, } }, }) ``` ### Database After generating schema with better-auth cli i pushed changes to database using drizzle. ![Image](https://github.com/user-attachments/assets/8e36338d-d8e5-4917-bbf5-4ea45767516f) ### Problem ```bash 2025-05-07T15:02:33.991Z ERROR [Better Auth]: Failed to create user 1 | class BetterAuthError extends Error { 2 | constructor(message, cause) { 3 | super(message); ^ BetterAuthError: The field "business_id" does not exist in the "customers" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate". cause: undefined, ```
Author
Owner

@ramsesndame237 commented on GitHub (May 11, 2025):

Hi! I'd like to work on this issue. Let me know if it's still available.

@ramsesndame237 commented on GitHub (May 11, 2025): Hi! I'd like to work on this issue. Let me know if it's still available.
Author
Owner

@mfazail commented on GitHub (May 13, 2025):

Yes, even i tried on a fresh project to test it with different package manager.

@mfazail commented on GitHub (May 13, 2025): Yes, even i tried on a fresh project to test it with different package manager.
Author
Owner

@Kinfe123 commented on GitHub (Jun 6, 2025):

To add additional fields, you can use the admin plugin to fill them out.

@Kinfe123 commented on GitHub (Jun 6, 2025): To add additional fields, you can use the admin plugin to fill them out.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1176