#1011·qmd

INSERT INTO content lacks OR IGNORE → SQLITE_CONSTRAINT_PRIMARYKEY when two files share identical content

Author: idirectshipsCreated Sep 28, 2026Updated Sep 28, 2026

Summary

When two files in the same collection have identical content, qmd update fails with:

SqliteError: SQLITE_CONSTRAINT_PRIMARYKEY: UNIQUE constraint failed: content.hash

The INSERT at store.ts (around line 2583) does not use INSERT OR IGNORE (or INSERT OR REPLACE), so a duplicate content hash causes a hard constraint violation rather than a graceful skip.

Version

qmd 2.6.3 (6dfc154)

Minimal repro

  1. Create a collection pointing at a directory with two or more files that share identical content (e.g., two empty __init__.py stubs or two auto-generated files with the same boilerplate).
  2. Run qmd update.
  3. Observe: SQLITE_CONSTRAINT_PRIMARYKEY on the second file's INSERT.

Suggested fix

Change the INSERT in store.ts around line 2583 from:

sql
INSERT INTO content (hash, ...) VALUES (?, ...)

to:

sql
INSERT OR IGNORE INTO content (hash, ...) VALUES (?, ...)

Since content is keyed by hash (content-addressable), a duplicate hash means the content is already stored — the second INSERT can safely be skipped.