Moving local assets to another synced folder after sync leads to remote only assets, re-upload and duplicate key value violation #5818

Closed
opened 2026-02-20 04:05:02 -05:00 by deekerman · 2 comments
Owner

Originally created by @timaschew on GitHub (Jun 18, 2025).

I have searched the existing issues, both open and closed, to make sure this is not a duplicate report.

  • Yes

The bug

When an asset is uploaded and then moved to another folder which is also backed up, the photo app doesn't recognize it and tries to upload it again. Which leads to a duplicate key value violates unique constraint "UQ_assets_owner_checksum" error.

It seems that the mobile app is not just using the hash of the file, but also the filepath.
Also on the "Photos" view the asset is shown as remote only after it's moved to another folder.

The OS that Immich Server is running on

Debian 12

Version of Immich Server

1.131.3

Version of Immich Mobile App

1.131.3

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

default

Your .env content

default

Reproduction steps

Steps for mobile:

  1. Select two folders in "Backup Albums" (folder1 and folder2)
  2. Start foreground backup and wait until a new photo (photo-x) is synced
  3. Use file manager to move photo-x from folder1 to folder2
  4. Start foreground backup again and see how photo-x is uploaded again
  5. in server logs you will see an error of course: duplicate key value violates unique constraint "UQ_assets_owner_checksum"

Relevant log output

immich_server              | [Nest] 17  - 06/17/2025, 9:51:03 PM     LOG [Api:EventRepository] Websocket Disconnect: 6q6URM9UxAxoW2-5AACl
immich_server              | [Nest] 17  - 06/17/2025, 9:51:26 PM     LOG [Api:EventRepository] Websocket Connect:    2Wd3kwon2K9Lf8OOAACn
immich_server              | Query failed : {
immich_server              |   durationMs: 4.196670001372695,
immich_server              |   error: PostgresError: duplicate key value violates unique constraint "UQ_assets_owner_checksum"
immich_server              |       at ErrorResponse (/usr/src/app/node_modules/postgres/cjs/src/connection.js:788:26)
immich_server              |       at handle (/usr/src/app/node_modules/postgres/cjs/src/connection.js:474:6)
immich_server              |       at Socket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:315:9)
immich_server              |       at Socket.emit (node:events:518:28)
immich_server              |       at addChunk (node:internal/streams/readable:561:12)
immich_server              |       at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
immich_server              |       at Readable.push (node:internal/streams/readable:392:5)
immich_server              |       at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
immich_server              |       at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
immich_server              |     severity_local: 'ERROR',
immich_server              |     severity: 'ERROR',
immich_server              |     code: '23505',
immich_server              |     detail: 'Key ("ownerId", checksum)=(295ba218-00ba-4bb9-95c9-b3417e765fb2, \\xf07fbd907275b181133fa338d320bde25f6b22dd) already exists.',
immich_server              |     schema_name: 'public',
immich_server              |     table_name: 'assets',
immich_server              |     constraint_name: 'UQ_assets_owner_checksum',
immich_server              |     file: 'nbtinsert.c',
immich_server              |     line: '663',
immich_server              |     routine: '_bt_check_unique'
immich_server              |   },
immich_server              |   sql: 'insert into "assets" ("ownerId", "libraryId", "checksum", "originalPath", "deviceAssetId", "deviceId", "fileCreatedAt", "fileModifiedAt", "localDateTime", "type", "isFavorite", "isArchived", "duration", "isVisible", "originalFileName") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) returning *',
immich_server              |   params: [
immich_server              |     '295ba218-00ba-4bb9-95c9-b3417e765fb2',
immich_server              |     null,
immich_server              |     <Buffer f0 7f bd 90 72 75 b1 81 13 3f a3 38 d3 20 bd e2 5f 6b 22 dd>,
immich_server              |     'upload/upload/295ba218-00ba-4bb9-95c9-b3417e765fb2/17/7c/177c64a8-993b-4c6a-b369-72adbdfa11ba.jpg',
immich_server              |     '16416',
immich_server              |     '10bbf38ab3ac0a24aea674661a9e73a2b5a5fbfca30e30ae3a1a111c704aee38',
immich_server              |     2025-06-17T19:49:15.000Z,
immich_server              |     2025-06-17T19:49:15.000Z,
immich_server              |     2025-06-17T19:49:15.000Z,
immich_server              |     'IMAGE',
immich_server              |     false,
immich_server              |     false,
immich_server              |     '0:00:00.000000',
immich_server              |     true,
immich_server              |     'IMG_20250617_214913955.jpg'
immich_server              |   ]
immich_server              | }

Additional information

No response

Originally created by @timaschew on GitHub (Jun 18, 2025). ### I have searched the existing issues, both open and closed, to make sure this is not a duplicate report. - [x] Yes ### The bug When an asset is uploaded and then moved to another folder which is also backed up, the photo app doesn't recognize it and tries to upload it again. Which leads to a `duplicate key value violates unique constraint "UQ_assets_owner_checksum"` error. It seems that the mobile app is not just using the hash of the file, but also the filepath. Also on the "Photos" view the asset is shown as remote only after it's moved to another folder. ### The OS that Immich Server is running on Debian 12 ### Version of Immich Server 1.131.3 ### Version of Immich Mobile App 1.131.3 ### Platform with the issue - [ ] Server - [ ] Web - [x] Mobile ### Your docker-compose.yml content ```YAML default ``` ### Your .env content ```Shell default ``` ### Reproduction steps Steps for mobile: 1. Select two folders in "Backup Albums" (folder1 and folder2) 2. Start foreground backup and wait until a new photo (photo-x) is synced 3. Use file manager to move photo-x from folder1 to folder2 4. Start foreground backup again and see how photo-x is uploaded again 5. in server logs you will see an error of course: `duplicate key value violates unique constraint "UQ_assets_owner_checksum"` ### Relevant log output ```shell immich_server | [Nest] 17 - 06/17/2025, 9:51:03 PM LOG [Api:EventRepository] Websocket Disconnect: 6q6URM9UxAxoW2-5AACl immich_server | [Nest] 17 - 06/17/2025, 9:51:26 PM LOG [Api:EventRepository] Websocket Connect: 2Wd3kwon2K9Lf8OOAACn immich_server | Query failed : { immich_server | durationMs: 4.196670001372695, immich_server | error: PostgresError: duplicate key value violates unique constraint "UQ_assets_owner_checksum" immich_server | at ErrorResponse (/usr/src/app/node_modules/postgres/cjs/src/connection.js:788:26) immich_server | at handle (/usr/src/app/node_modules/postgres/cjs/src/connection.js:474:6) immich_server | at Socket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:315:9) immich_server | at Socket.emit (node:events:518:28) immich_server | at addChunk (node:internal/streams/readable:561:12) immich_server | at readableAddChunkPushByteMode (node:internal/streams/readable:512:3) immich_server | at Readable.push (node:internal/streams/readable:392:5) immich_server | at TCP.onStreamRead (node:internal/stream_base_commons:189:23) immich_server | at TCP.callbackTrampoline (node:internal/async_hooks:130:17) { immich_server | severity_local: 'ERROR', immich_server | severity: 'ERROR', immich_server | code: '23505', immich_server | detail: 'Key ("ownerId", checksum)=(295ba218-00ba-4bb9-95c9-b3417e765fb2, \\xf07fbd907275b181133fa338d320bde25f6b22dd) already exists.', immich_server | schema_name: 'public', immich_server | table_name: 'assets', immich_server | constraint_name: 'UQ_assets_owner_checksum', immich_server | file: 'nbtinsert.c', immich_server | line: '663', immich_server | routine: '_bt_check_unique' immich_server | }, immich_server | sql: 'insert into "assets" ("ownerId", "libraryId", "checksum", "originalPath", "deviceAssetId", "deviceId", "fileCreatedAt", "fileModifiedAt", "localDateTime", "type", "isFavorite", "isArchived", "duration", "isVisible", "originalFileName") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) returning *', immich_server | params: [ immich_server | '295ba218-00ba-4bb9-95c9-b3417e765fb2', immich_server | null, immich_server | <Buffer f0 7f bd 90 72 75 b1 81 13 3f a3 38 d3 20 bd e2 5f 6b 22 dd>, immich_server | 'upload/upload/295ba218-00ba-4bb9-95c9-b3417e765fb2/17/7c/177c64a8-993b-4c6a-b369-72adbdfa11ba.jpg', immich_server | '16416', immich_server | '10bbf38ab3ac0a24aea674661a9e73a2b5a5fbfca30e30ae3a1a111c704aee38', immich_server | 2025-06-17T19:49:15.000Z, immich_server | 2025-06-17T19:49:15.000Z, immich_server | 2025-06-17T19:49:15.000Z, immich_server | 'IMAGE', immich_server | false, immich_server | false, immich_server | '0:00:00.000000', immich_server | true, immich_server | 'IMG_20250617_214913955.jpg' immich_server | ] immich_server | } ``` ### Additional information _No response_
deekerman 2026-02-20 04:05:02 -05:00
Author
Owner

@ngdangtu-vn commented on GitHub (Jul 22, 2025):

I found a error log in my server that maybe relates to this issue?

Query failed : {
  durationMs: 13.25985400006175,
  error: PostgresError: duplicate key value violates unique constraint "UQ_assets_owner_checksum"
      at ErrorResponse (/usr/src/app/node_modules/postgres/cjs/src/connection.js:790:26)
      at handle (/usr/src/app/node_modules/postgres/cjs/src/connection.js:476:6)
      at Socket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:315:9)
      at Socket.emit (node:events:518:28)
      at addChunk (node:internal/streams/readable:561:12)
      at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
      at Readable.push (node:internal/streams/readable:392:5)
      at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
      at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
    severity_local: 'ERROR',
    severity: 'ERROR',
    code: '23505',
    detail: 'Key ("ownerId", checksum)=(20097e3a-aa2b-47a1-9150-3ee91648d012, \\x98a52d2503a2e8c2565af0d52771c94f353636be) already exists.',
    schema_name: 'public',
    table_name: 'assets',
    constraint_name: 'UQ_assets_owner_checksum',
    file: 'nbtinsert.c',
    line: '663',
    routine: '_bt_check_unique'
  },
  sql: 'insert into "assets" ("ownerId", "libraryId", "checksum", "originalPath", "deviceAssetId", "deviceId", "fileCreatedAt", "fileModifiedAt", "localDateTime", "type", "isFavorite", "duration", "visibility", "originalFileName") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) returning *',
  params: [
    '20097e3a-aa2b-47a1-9150-3ee91648d012',
    null,
    <Buffer 98 a5 2d 25 03 a2 e8 c2 56 5a f0 d5 27 71 c9 4f 35 36 36 be>,
    'upload/upload/20097e3a-aa2b-47a1-9150-3ee91648d012/46/f8/46f8cd17-5d4e-4b18-b900-3f6ea7ab5b77.jpg',
    '1000004211',
    '2d50f8e0e541db0844a4121f4552038e5310e6f46b4ad8ed20868c3d19ee66ed',
    2022-12-18T08:31:12.000Z,
    2022-12-18T08:31:12.000Z,
    2022-12-18T08:31:12.000Z,
    'IMAGE',
    false,
    '0:00:00.000000',
    'timeline',
    '20221218_153111.jpg'
  ]
}

If so then this could also be a part of this problem #20093 and #2567

@ngdangtu-vn commented on GitHub (Jul 22, 2025): I found a error log in my server that maybe relates to this issue? ``` Query failed : { durationMs: 13.25985400006175, error: PostgresError: duplicate key value violates unique constraint "UQ_assets_owner_checksum" at ErrorResponse (/usr/src/app/node_modules/postgres/cjs/src/connection.js:790:26) at handle (/usr/src/app/node_modules/postgres/cjs/src/connection.js:476:6) at Socket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:315:9) at Socket.emit (node:events:518:28) at addChunk (node:internal/streams/readable:561:12) at readableAddChunkPushByteMode (node:internal/streams/readable:512:3) at Readable.push (node:internal/streams/readable:392:5) at TCP.onStreamRead (node:internal/stream_base_commons:189:23) at TCP.callbackTrampoline (node:internal/async_hooks:130:17) { severity_local: 'ERROR', severity: 'ERROR', code: '23505', detail: 'Key ("ownerId", checksum)=(20097e3a-aa2b-47a1-9150-3ee91648d012, \\x98a52d2503a2e8c2565af0d52771c94f353636be) already exists.', schema_name: 'public', table_name: 'assets', constraint_name: 'UQ_assets_owner_checksum', file: 'nbtinsert.c', line: '663', routine: '_bt_check_unique' }, sql: 'insert into "assets" ("ownerId", "libraryId", "checksum", "originalPath", "deviceAssetId", "deviceId", "fileCreatedAt", "fileModifiedAt", "localDateTime", "type", "isFavorite", "duration", "visibility", "originalFileName") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) returning *', params: [ '20097e3a-aa2b-47a1-9150-3ee91648d012', null, <Buffer 98 a5 2d 25 03 a2 e8 c2 56 5a f0 d5 27 71 c9 4f 35 36 36 be>, 'upload/upload/20097e3a-aa2b-47a1-9150-3ee91648d012/46/f8/46f8cd17-5d4e-4b18-b900-3f6ea7ab5b77.jpg', '1000004211', '2d50f8e0e541db0844a4121f4552038e5310e6f46b4ad8ed20868c3d19ee66ed', 2022-12-18T08:31:12.000Z, 2022-12-18T08:31:12.000Z, 2022-12-18T08:31:12.000Z, 'IMAGE', false, '0:00:00.000000', 'timeline', '20221218_153111.jpg' ] } ``` If so then this could also be a part of this problem #20093 and #2567
Author
Owner

@shenlong-tanwen commented on GitHub (Sep 11, 2025):

This should be fixed with the beta timeline implementation where we check if the same asset exists on the server before uploading it again.

@shenlong-tanwen commented on GitHub (Sep 11, 2025): This should be fixed with the beta timeline implementation where we check if the same asset exists on the server before uploading it again.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/immich#5818
No description provided.