cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.58k stars 663 forks source link

🐛 BUG: wrangler d1 export #6599

Open nferch opened 2 weeks ago

nferch commented 2 weeks ago

Which Cloudflare product(s) does this pertain to?

D1

What version(s) of the tool(s) are you using?

3.72.3 [Wrangler]

What version of Node are you using?

v18.19.1

What operating system and version are you using?

Sonoma 14.6.1

Describe the Bug

Observed behavior

wrangler d1 export fails with the error message ✘ [ERROR] near "from": syntax error at offset 28: SQLITE_ERROR

Expected behavior

wrangler d1 export succeeds, creating a SQL file.

Steps to reproduce

CREATE TABLE IF NOT EXISTS "Message" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "status" TEXT,
    "from" TEXT NOT NULL,
    "to" TEXT NOT NULL,
    "subject" TEXT NOT NULL,
    "body" TEXT NOT NULL
);

Attempt to export the database, e.g.

wrangler d1 export testdb --remote --output foo.sql

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

SirRodney commented 1 week ago

I encountered the same error when trying to export a database using wrangler d1 export. In my case, I was able to resolve the issue by renaming the "from" column to something else, as it seems that "from" might be causing the problem due to being a reserved word in SQL. After renaming the column, the export completed successfully.

You might want to try renaming "from" to something like "sender" or "from_address" and see if that fixes the issue.

Hope this helps!

nferch commented 1 week ago

Great shout @SirRodney . Turns out both from and to were problematic

codenoid commented 1 week ago

oh my god, thanks guys, I'm having limit as a column name

near "limit": syntax error at offset 40: SQLITE_ERROR

RamIdeas commented 6 days ago

@rozenmd can we use quoted-strings to workaround this issue or add a note about this limitation in the docs (eg. "cannot use reserved SQL keywords as column names")