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.hashThe 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
- Create a collection pointing at a directory with two or more files that share identical content (e.g., two empty
__init__.pystubs or two auto-generated files with the same boilerplate). - Run
qmd update. - Observe:
SQLITE_CONSTRAINT_PRIMARYKEYon the second file's INSERT.
Suggested fix
Change the INSERT in store.ts around line 2583 from:
INSERT INTO content (hash, ...) VALUES (?, ...)to:
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.
Source: tobi/qmd