workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 BUG: `wrangler d1 export` writes `ERROR near...` to output file

Open hrueger opened this issue 1 year ago • 1 comments

Which Cloudflare product(s) does this pertain to?

D1

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

3.57.1 [Wrangler]

What version of Node are you using?

v21.6.1

What operating system and version are you using?

macOS Sonoma 14.4.1

Describe the Bug

Observed behavior

When running npx wrangler d1 export my-db --remote --output myfile.sql, I get some tables, but then ERROR near "default": syntax error at offset 39. Here's the end of the file:

[ here are some CREATE TABLE IF NOT EXISTS and INSERT INTO queries ]
CREATE TABLE IF NOT EXISTS "Layout" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    "name" TEXT NOT NULL,
    "default" BOOLEAN NOT NULL DEFAULT false,
    "active" BOOLEAN NOT NULL DEFAULT false,
    "media" TEXT NOT NULL,
    "objects" TEXT NOT NULL,
    "a4Options" TEXT NOT NULL,
    "ticketOptions" TEXT NOT NULL,
    "walletOptions" TEXT NOT NULL,
    "plasticCardOptions" TEXT NOT NULL,
    "receiptOptions" TEXT NOT NULL,
    "organizationId" TEXT,
    CONSTRAINT "Layout_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
ERROR near "default": syntax error at offset 39

Expected behavior

It exports correctly.

Steps to reproduce

To be honest, I don't know. The Layout table contains some entries with JSON strings, but those are just {}. Maybe the column called default is the problem?

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

hrueger avatar May 26 '24 07:05 hrueger

Yes, the default column is indeed the culprit. I renamed it to isDefault and it worked just fine.

hrueger avatar May 26 '24 07:05 hrueger