The table `main.verification` does not exist in the current database.
hey - trying to use better-auth with hono on cloudflare pages, currently just with a local database. Got hono and the database talking, tried to add better-auth with prisma, and I'm getting the following error:
``
<-- POST /start-sign-in
/start-sign-in sees email [email protected]
c.env.DATABASE_URL undefined
<-- POST /api/auth/email-otp/send-verification-otp
# SERVER_ERROR: PrismaClientKnownRequestError:
Invalid
prisma.verification.create() invocation:
The table
main.verification` does not exist in the current database.
at zn.handleRequestError (/Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/@prisma/client/runtime/library.js:121:7459)
at zn.handleAndLogRequestError (/Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/@prisma/client/runtime/library.js:121:6784)
at zn.request (/Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/@prisma/client/runtime/library.js:121:6491)
at async l (/Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/@prisma/client/runtime/library.js:130:9778)
at async Object.create (file:///Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/better-auth/dist/adapters/prisma-adapter/index.mjs:92:16)
at async Object.create (file:///Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/better-auth/dist/shared/better-auth.rSYJCd3o.mjs:388:19)
at async createWithHooks (file:///Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/better-auth/dist/shared/better-auth.Bk5IMdhM.mjs:49:71)
coninued in comment7 Replies
continued from main post
at async Object.createVerificationValue (file:///Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/better-auth/dist/shared/better-auth.Bk5IMdhM.mjs:746:28)
at async file:///Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/better-auth/dist/plugins/email-otp/index.mjs:124:13
at async file:///Users/chris/hacks/podcast-time-machine/experiments/tmp/hono-prisma-d1/node_modules/better-auth/dist/plugins/email-otp/index.mjs:116:11 {
code: 'P2021',
meta: { modelName: 'Verification', table: 'main.verification' },
clientVersion: '6.6.0'
}
--> POST /api/auth/email-otp/send-verification-otp 500 26ms
/start-sign-in sees error { status: 500, statusText: 'Internal Server Error' }
/start-sign-in sees data null
--> POST /start-sign-in 302 53ms
```
Any clues about what to do here VERY much appreciated!
have you generated the prisma schema file and push to your db ?
I did:
npx prisma generate
wrangler d1 migrations apply hpd1-db --local
Those succeeded, but I get the same error.
can i see your db config for creating a prisma client
may be you are using the wrong prisma client
and make sure to send also your prisma schema file
@KiNFiSH (sorry to take a while to get back)
My prisma/schema.prisma file:
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
// change from default
}
datasource db {
provider = "sqlite"
// d1 is sql base database
url = env("DATABASE_URL")
}
// Create a simple model database
model User {
id String @id @default(uuid())
email String @unique
name String?
emailVerified Boolean
image String?
createdAt DateTime
updatedAt DateTime
sessions Session[]
accounts Account[]
@@map("user")
}
// Create a simple count database
model Count {
id String @id @default(uuid())
count Int
}
model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime
updatedAt DateTime
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([token])
@@map("session")
}
model Account {
id String @id
accountId String
providerId String
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
accessToken String?
refreshToken String?
idToken String?
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
scope String?
password String?
createdAt DateTime
updatedAt DateTime
@@map("account")
}
model Verification {
id String @id
identifier String
value String
expiresAt DateTime
createdAt DateTime?
updatedAt DateTime?
@@map("verification")
}
Here is src/lib/prismaClient.ts
import { PrismaClient } from '@prisma/client'
import { PrismaD1 } from '@prisma/adapter-d1'
const prismaClients = {
async fetch(db: D1Database) {
const adapter = new PrismaD1(db)
return new PrismaClient({ adapter })
},
}
export default prismaClients
Did you see your tables existed after the push ?
Yes
(I presume you mean in the sqlite3 database)