i'm building a nextjs app on pages, and

i'm building a nextjs app on pages, and i want to bind it to a D1 database. i created a D1 database & created a new table, but it seems that i can't connect to it when developing locally. wrangler.toml [[d1_databases]] binding = "D1" database_name = "d1-prod" database_id = "...." command to start local dev: npm run dev (next dev) in app: const results = await env.D1.prepare("SELECT * FROM users").all(); fails with: Cause: Error: no such table: users at D1Database._sendOrThrow (cloudflare-internal:d1-api:67:24) at async D1PreparedStatement.all (cloudflare-internal:d1-api:181:46) { [cause]: undefined } ⨯ Error: D1_ERROR: no such table: users at async Page (page.tsx:37:21) digest: "1859585598" Cause: Error: no such table: users at D1Database._sendOrThrow (cloudflare-internal:d1-api:67:24) at async D1PreparedStatement.all (cloudflare-internal:d1-api:181:46) { [cause]: undefined } GET / 500 in 3152ms in the docs, i see that there's a way to pass the --d1 flag when using wrangler pages dev, but that's not compatible with next dev, so not sure what to do
1 Reply
kchro3
kchro3OP7mo ago
ok, i see the threads in the pages-help saying that it isn't supported yet. if anyone else comes across this, so far, what i've done is:
wrangler d1 export <name> --output tmp.sql --remote
wrangler d1 execute <name> --file tmp.sql --local
wrangler d1 export <name> --output tmp.sql --remote
wrangler d1 execute <name> --file tmp.sql --local
Want results from more Discord servers?
Add your server