Drizzle ORM Schema
Hello, I was just trying to use better-auth with drizzleORM. But when I did the drizzle-kit generate and drizzle-kit migrate I got this error:
#22 8.238
#22 11.07 42 | });
#22 11.07 43 | }
#22 11.07 44 |
#22 11.07 45 | execute(query, params) {
#22 11.07 46 | const c = this.connection;
#22 11.07 47 | const localErr = new Error();
#22 11.07 ^
#22 11.07 error: Can't create table
api
.account
(errno: 150 "Foreign key constraint is incorrectly formed")
#22 11.07 errno: 1005,
#22 11.07 sql: "ALTER TABLE account
ADD CONSTRAINT account_user_id_user_id_fk
FOREIGN KEY (user_id
) REFERENCES user
(id
) ON DELETE cascade ON UPDATE no action;",
#22 11.07 sqlState: "HY000",
#22 11.07 sqlMessage: "Can't create table api
.account
(errno: 150 "Foreign key constraint is incorrectly formed")",
#22 11.07 code: "ER_CANT_CREATE_TABLE"
#22 11.07
#22 11.07 at execute (/app/node_modules/mysql2/lib/promise/connection.js:47:22)
#22 11.07 at <anonymous> (/app/node_modules/drizzle-kit/bin.cjs:79120:40)
#22 11.07 at query (/app/node_modules/drizzle-kit/bin.cjs:79119:35)
#22 11.07 at <anonymous> (/app/node_modules/drizzle-kit/bin.cjs:82230:22)
#22 11.07
#22 DONE 11.3s
This are my auth files:
db.ts:
3 Replies
auth-schema.ts:
I just did the
npx @better-auth/cli@latest generate
npx drizzle-kit generate
npx drizzle-kit migrate
and got the error
could be a size mismatch between session/account userId foreign key and the actual user.id column.
id => is varchar(36)
userId => text
try:
it worked, thanks :)