No such table

I've written a simple Workers script locally to get some data from D1
import { Router } from 'itty-router';

const router = Router();

export interface Env {
kirbyDB: D1Database;
}

router.get('/kirby', async (_, env: Env) => {
const { results } = await env.kirbyDB.prepare('SELECT * FROM game').all();
console.log(results);
return new Response('kirby');
});

export default {
fetch: router.handle,
};
import { Router } from 'itty-router';

const router = Router();

export interface Env {
kirbyDB: D1Database;
}

router.get('/kirby', async (_, env: Env) => {
const { results } = await env.kirbyDB.prepare('SELECT * FROM game').all();
console.log(results);
return new Response('kirby');
});

export default {
fetch: router.handle,
};
In wrangler.toml I bind it like this
name = "learn-workers"
main = "src/worker.ts"
compatibility_date = "2023-06-15"

[[d1_databases]]
binding = "kirbyDB"
database_name = "kirby"
database_id = "7d96fcb0-da44-4d95-ae22-8fd7101e7045"
name = "learn-workers"
main = "src/worker.ts"
compatibility_date = "2023-06-15"

[[d1_databases]]
binding = "kirbyDB"
database_name = "kirby"
database_id = "7d96fcb0-da44-4d95-ae22-8fd7101e7045"
In the Cloudflare Dashboard above I set up the database like this I think the database should be fine, because I can access it using wrangler
โฏ wrangler d1 execute kirby --command "SELECT * FROM game"

๐ŸŒ€ Mapping SQL input into an array of statements
๐ŸŒ€ Parsing 1 statements
๐ŸŒ€ Executing on kirby (7d96fcb0-da44-4d95-ae22-8fd7101e7045):
๐Ÿšฃ Executed 1 commands in 4.9073589984327555ms
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ console โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ gba โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ sfc โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โฏ wrangler d1 execute kirby --command "SELECT * FROM game"

๐ŸŒ€ Mapping SQL input into an array of statements
๐ŸŒ€ Parsing 1 statements
๐ŸŒ€ Executing on kirby (7d96fcb0-da44-4d95-ae22-8fd7101e7045):
๐Ÿšฃ Executed 1 commands in 4.9073589984327555ms
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ console โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ gba โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ sfc โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
But in the script I get this error
[mf:err] Cause: Error: Error: SqliteError: no such table: game
[mf:err] Cause: Error: Error: SqliteError: no such table: game
Did I make a mistake or something? GitHub Issues link: https://github.com/cloudflare/workers-sdk/issues/3479
GitHub
๐Ÿ› BUG: No such table ยท Issue #3479 ยท cloudflare/workers-sdk
Which Cloudflare product(s) does this pertain to? D1, Workers/Other, Wrangler What version of Wrangler are you using? 3.1.0 What operating system are you using? Windows 11 Describe the Bug I've...
5 Replies
Chaika
Chaikaโ€ข2y ago
Looks like remote vs local dev confusion Wrangler 3.x defaults to local dev, if you want to use remote dev which uses the actual db, use wrangler dev --remote If you want your wrangler D1 commands to effect the local dev db instead of remote, use --local, like wrangler d1 execute <DATABASE_NAME> --local --command='SELECT * FROM Customers'
Chaika
Chaikaโ€ข2y ago
There's a helpful doc here that explains it all: https://developers.cloudflare.com/d1/learning/local-development/
Local development ยท Cloudflare D1 docs
D1 has fully-featured support for local development, running the same version of D1 as Cloudflare runs globally. Local development uses Wrangler, the โ€ฆ
Yanren
YanrenOPโ€ข2y ago
I get this error with wrangler dev --remote is this a problem with my local network?
X [ERROR] Error while creating remote dev session: TypeError: fetch failed

at fetch
(C:\Users\nihaocun\AppData\Local\pnpm\global\5\.pnpm\[email protected]\node_modules\wrangler\wrangler-dist\cli.js:16584:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async createPreviewSession
(C:\Users\nihaocun\AppData\Local\pnpm\global\5\.pnpm\[email protected]\node_modules\wrangler\wrangler-dist\cli.js:128441:28)
at async start
(C:\Users\nihaocun\AppData\Local\pnpm\global\5\.pnpm\[email protected]\node_modules\wrangler\wrangler-dist\cli.js:147908:9)
{
cause: Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
}
X [ERROR] Error while creating remote dev session: TypeError: fetch failed

at fetch
(C:\Users\nihaocun\AppData\Local\pnpm\global\5\.pnpm\[email protected]\node_modules\wrangler\wrangler-dist\cli.js:16584:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async createPreviewSession
(C:\Users\nihaocun\AppData\Local\pnpm\global\5\.pnpm\[email protected]\node_modules\wrangler\wrangler-dist\cli.js:128441:28)
at async start
(C:\Users\nihaocun\AppData\Local\pnpm\global\5\.pnpm\[email protected]\node_modules\wrangler\wrangler-dist\cli.js:147908:9)
{
cause: Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
}
Chaika
Chaikaโ€ข2y ago
Possibly? That's interesting, there's a few mentions/issues with that on the workers sdk repo recently. Not something I've hit myself before, someone said it worked after a few retries, or you could try local dev
Yanren
YanrenOPโ€ข2y ago
Ok thank you, I'll try a few more times later
Want results from more Discord servers?
Add your server