payloadcms / payloadcms/payload
SQLite/D1: Reserved keyword `order` not quoted in CREATE INDEX statements
@r1tsuu is already working on this.
Since Feb 4, 2026.
- 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
- Create a Payload CMS project with
@payloadcms/db-sqliteor@payloadcms/db-d1-sqlite - Add any collection with a relationship field (which creates
*_relstables) - 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_relspages_relsposts_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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.