payloadcms / payloadcms/payload

SQLite/D1: Reserved keyword `order` not quoted in CREATE INDEX statements

Open
#15,482 0 comments 0 reactions 1 assignee View on GitHub

@r1tsuu is already working on this.

Since Feb 4, 2026.

db: d1-sqlite
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Describe the Bug

The SQLite/D1 adapter generates CREATE INDEX statements without quoting the order column name, which is a reserved SQL keyword. This causes migrations to fail with a syntax error.

To Reproduce

  1. Create a Payload CMS project with @payloadcms/db-sqlite or @payloadcms/db-d1-sqlite
  2. Add any collection with a relationship field (which creates *_rels tables)
  3. Run migrations

Error Message

Runtime Error: Failed query: CREATE INDEX \`payload_locked_documents_rels_order_idx\` ON \`payload_locked_documents_rels\` (\`order\`);

Note: The error occurs because order is unquoted in the index column reference.

Expected Behavior

The order column should be quoted with backticks in all CREATE INDEX statements:

-- ❌ Current (fails)
CREATE INDEX \`payload_locked_documents_rels_order_idx\` ON \`payload_locked_documents_rels\` (order);

-- ✅ Expected (works)
CREATE INDEX \`payload_locked_documents_rels_order_idx\` ON \`payload_locked_documents_rels\` (\`order\`);

Affected Tables

All *_rels tables that have an order column:

  • payload_locked_documents_rels
  • pages_rels
  • posts_rels
  • (any collection with relationships)

Environment

  • Payload Version: 3.x
  • Adapter: @payloadcms/db-d1-sqlite (also likely affects @payloadcms/db-sqlite)
  • Database: Cloudflare D1 / SQLite

Workaround

Manually edit generated migration files to quote the order column in CREATE INDEX statements:

- CREATE INDEX \`payload_locked_documents_rels_order_idx\` ON \`payload_locked_documents_rels\` (order);
+ CREATE INDEX \`payload_locked_documents_rels_order_idx\` ON \`payload_locked_documents_rels\` (\`order\`);

Additional Context

The CREATE TABLE statements correctly quote order, but CREATE INDEX statements don't. This inconsistency suggests the quoting logic is missing in the index generation code path.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.