Custom tables - The field "userId" does not exist in the schema for the model "account"

I have an issue with my custom tables. I edited userId from account table but i dont understand why it doesn't work propertly.
I get this error:
[A [BetterAuthError]: The field "userId" does not exist in the schema for the model "account". Please update your schema.] {
  cause: undefined
}
auth.ts
import dotenv from "dotenv";
import { betterAuth } from "better-auth";
import { admin, organization } from "better-auth/plugins";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { v7 as uuidv7 } from "uuid";
import argon2 from "argon2";
import { db } from "../db/drizzle";
import { accounts, operators } from "../db/schema/auth-schema";

dotenv.config();

const argon2Verify = async (data: { hash: string; password: string }): Promise<boolean> => {
    const { hash, password } = data;
    return argon2.verify(hash, password);
};

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: "pg",
        usePlural: true,
        schema: {
            operators,
            accounts,
        },
    }),
    plugins: [
        admin(),
        organization({
            allowUserToCreateOrganization: async () => false,
        }),
    ],
    emailAndPassword: {
        enabled: true,
        password: {
            hash: argon2.hash,
            verify: argon2Verify,
        },
    },
    user: {
        modelName: "operators",
    },
    account: {
        fields: {
            userId: "operation_id",
        },
    },
});
Screenshot_from_2025-01-02_07-35-50.png
Screenshot_from_2025-01-02_07-36-42.png
Was this page helpful?