[BUG] Update to v1.48.1 fails due to failed migration #705

Closed
opened 2026-02-04 22:01:14 +03:00 by OVERLORD · 3 comments
Owner

Originally created by @cmintey on GitHub (Feb 22, 2023).

The bug

Updating from v1.47.3 to v1.48.1 results in the server not being able to start.

immich_server         | Migration "FixAssetRelations1676680127415" failed, error: insert or update on table "assets" violates foreign key constraint "FK_16294b83fa8c0149719a1f631ef"
immich_server         | [Nest] 1  - 02/22/2023, 5:37:12 PM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (3)...
immich_server         | QueryFailedError: insert or update on table "assets" violates foreign key constraint "FK_16294b83fa8c0149719a1f631ef"
immich_server         |     at PostgresQueryRunner.query (/usr/src/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19)
immich_server         |     at processTicksAndRejections (node:internal/process/task_queues:96:5)
immich_server         |     at async FixAssetRelations1676680127415.up (/usr/src/app/dist/apps/immich/libs/infra/src/db/migrations/1676680127415-FixAssetRelations.js:15:9)
immich_server         |     at async MigrationExecutor.executePendingMigrations (/usr/src/app/node_modules/typeorm/migration/MigrationExecutor.js:223:17)
immich_server         |     at async DataSource.runMigrations (/usr/src/app/node_modules/typeorm/data-source/DataSource.js:249:35)
immich_server         |     at async DataSource.initialize (/usr/src/app/node_modules/typeorm/data-source/DataSource.js:137:17)
immich_postgres       | 2023-02-22 17:37:16.414 UTC [39] ERROR:  insert or update on table "assets" violates foreign key constraint "FK_16294b83fa8c0149719a1f631ef"
immich_postgres       | 2023-02-22 17:37:16.414 UTC [39] DETAIL:  Key (livePhotoVideoId)=(111f65b7-962e-46be-962f-b78b577c4da3) is not present in table "assets".
immich_postgres       | 2023-02-22 17:37:16.414 UTC [39] STATEMENT:  ALTER TABLE "assets" ADD CONSTRAINT "FK_16294b83fa8c0149719a1f631ef" FOREIGN KEY ("livePhotoVideoId") REFERENCES "assets"("id") ON DELETE SET NULL ON UPDATE CASCADE

The OS that Immich Server is running on

Ubuntu 22.04 LTS, arm64

Version of Immich Server

v1.48.1

Version of Immich Mobile App

v1.48.1

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

version: "3.8"

services:
  immich-server:
    container_name: immich_server
    image: altran1502/immich-server:v1.48.1
    entrypoint: ["/bin/sh", "./start-server.sh"]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
    env_file:
      - .env
    environment:
      - NODE_ENV=production
    depends_on:
      - redis
      - database
    restart: always

  immich-microservices:
    container_name: immich_microservices
    image: altran1502/immich-server:v1.48.1
    entrypoint: ["/bin/sh", "./start-microservices.sh"]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
    env_file:
      - .env
    environment:
      - NODE_ENV=production
    depends_on:
      - redis
      - database
    restart: always

  immich-web:
    container_name: immich_web
    image: altran1502/immich-web:v1.48.1
    entrypoint: ["/bin/sh", "./entrypoint.sh"]
    env_file:
      - .env
    restart: always

  redis:
    container_name: immich_redis
    image: redis:6.2
    restart: always

  database:
    container_name: immich_postgres
    image: postgres:14
    env_file:
      - .env
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      PG_DATA: /var/lib/postgresql/data
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: always

  immich-proxy:
    container_name: immich_proxy
    image: altran1502/immich-proxy:v1.48.1
    environment:
      # Make sure these values get passed through from the env file
      - IMMICH_SERVER_URL
      - IMMICH_WEB_URL
    ports:
      - 2283:8080
    logging:
      driver: none
    depends_on:
      - immich-server
    restart: always

volumes:
  pgdata:

Your .env content

DB_HOSTNAME=immich_postgres
DB_USERNAME=postgres
DB_PASSWORD=<REDACTED>
DB_DATABASE_NAME=immich

REDIS_HOSTNAME=immich_redis

UPLOAD_LOCATION=./data

PUBLIC_LOGIN_PAGE_MESSAGE=

IMMICH_WEB_URL=http://immich_web:3000
IMMICH_SERVER_URL=http://immich_server:3001

Reproduction steps

1. Update to v1.48.1
2. Unable to connect to app via web or app
3. Checked the logs and saw migration error

Additional information

No response

Originally created by @cmintey on GitHub (Feb 22, 2023). ### The bug Updating from v1.47.3 to v1.48.1 results in the server not being able to start. ```sh immich_server | Migration "FixAssetRelations1676680127415" failed, error: insert or update on table "assets" violates foreign key constraint "FK_16294b83fa8c0149719a1f631ef" immich_server | [Nest] 1 - 02/22/2023, 5:37:12 PM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (3)... immich_server | QueryFailedError: insert or update on table "assets" violates foreign key constraint "FK_16294b83fa8c0149719a1f631ef" immich_server | at PostgresQueryRunner.query (/usr/src/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19) immich_server | at processTicksAndRejections (node:internal/process/task_queues:96:5) immich_server | at async FixAssetRelations1676680127415.up (/usr/src/app/dist/apps/immich/libs/infra/src/db/migrations/1676680127415-FixAssetRelations.js:15:9) immich_server | at async MigrationExecutor.executePendingMigrations (/usr/src/app/node_modules/typeorm/migration/MigrationExecutor.js:223:17) immich_server | at async DataSource.runMigrations (/usr/src/app/node_modules/typeorm/data-source/DataSource.js:249:35) immich_server | at async DataSource.initialize (/usr/src/app/node_modules/typeorm/data-source/DataSource.js:137:17) ``` ```sh immich_postgres | 2023-02-22 17:37:16.414 UTC [39] ERROR: insert or update on table "assets" violates foreign key constraint "FK_16294b83fa8c0149719a1f631ef" immich_postgres | 2023-02-22 17:37:16.414 UTC [39] DETAIL: Key (livePhotoVideoId)=(111f65b7-962e-46be-962f-b78b577c4da3) is not present in table "assets". immich_postgres | 2023-02-22 17:37:16.414 UTC [39] STATEMENT: ALTER TABLE "assets" ADD CONSTRAINT "FK_16294b83fa8c0149719a1f631ef" FOREIGN KEY ("livePhotoVideoId") REFERENCES "assets"("id") ON DELETE SET NULL ON UPDATE CASCADE ``` ### The OS that Immich Server is running on Ubuntu 22.04 LTS, arm64 ### Version of Immich Server v1.48.1 ### Version of Immich Mobile App v1.48.1 ### Platform with the issue - [X] Server - [ ] Web - [ ] Mobile ### Your docker-compose.yml content ```YAML version: "3.8" services: immich-server: container_name: immich_server image: altran1502/immich-server:v1.48.1 entrypoint: ["/bin/sh", "./start-server.sh"] volumes: - ${UPLOAD_LOCATION}:/usr/src/app/upload env_file: - .env environment: - NODE_ENV=production depends_on: - redis - database restart: always immich-microservices: container_name: immich_microservices image: altran1502/immich-server:v1.48.1 entrypoint: ["/bin/sh", "./start-microservices.sh"] volumes: - ${UPLOAD_LOCATION}:/usr/src/app/upload env_file: - .env environment: - NODE_ENV=production depends_on: - redis - database restart: always immich-web: container_name: immich_web image: altran1502/immich-web:v1.48.1 entrypoint: ["/bin/sh", "./entrypoint.sh"] env_file: - .env restart: always redis: container_name: immich_redis image: redis:6.2 restart: always database: container_name: immich_postgres image: postgres:14 env_file: - .env environment: POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_USER: ${DB_USERNAME} POSTGRES_DB: ${DB_DATABASE_NAME} PG_DATA: /var/lib/postgresql/data volumes: - pgdata:/var/lib/postgresql/data restart: always immich-proxy: container_name: immich_proxy image: altran1502/immich-proxy:v1.48.1 environment: # Make sure these values get passed through from the env file - IMMICH_SERVER_URL - IMMICH_WEB_URL ports: - 2283:8080 logging: driver: none depends_on: - immich-server restart: always volumes: pgdata: ``` ### Your .env content ```Shell DB_HOSTNAME=immich_postgres DB_USERNAME=postgres DB_PASSWORD=<REDACTED> DB_DATABASE_NAME=immich REDIS_HOSTNAME=immich_redis UPLOAD_LOCATION=./data PUBLIC_LOGIN_PAGE_MESSAGE= IMMICH_WEB_URL=http://immich_web:3000 IMMICH_SERVER_URL=http://immich_server:3001 ``` ### Reproduction steps ```bash 1. Update to v1.48.1 2. Unable to connect to app via web or app 3. Checked the logs and saw migration error ``` ### Additional information _No response_
Author
Owner

@alextran1502 commented on GitHub (Feb 22, 2023):

This is related to FK enforcement, which we added in the update. Would you mind heading over the Discord, and we can jump into writing to query to sort this out?

@alextran1502 commented on GitHub (Feb 22, 2023): This is related to FK enforcement, which we added in the update. Would you mind heading over the Discord, and we can jump into writing to query to sort this out?
Author
Owner

@cmintey commented on GitHub (Feb 22, 2023):

Hey thanks for the quick response. I saw your help on this post and was able to adapt your instructions.

I fixed the issue by deleting the asset in question. I'll put my queries here for future people to stumble on...

Get into your postgres container to run SQL queries:

docker exec -it immich_postgres psql -U postgres -d immich

Check out the missing asset in question.

immich=# select * from assets where "livePhotoVideoId" = '111f65b7-962e-46be-962f-b78b577c4da3';
<large output>
(1 row)

This spit out a large output, but the part I needed was id: 73bf3a56-8df1-4928-9817-1efd0122d21c

Then I checked to see if the live photo video asset existed...

immich=# select * from assets where "id" = '111f65b7-962e-46be-962f-b78b577c4da3';
(0 rows)

Turns out it didn't. So I just deleted this asset

immich=# delete from assets where "id" = '73bf3a56-8df1-4928-9817-1efd0122d21c';
DELETE 1

Restarted my stack and the migration was successful.

@cmintey commented on GitHub (Feb 22, 2023): Hey thanks for the quick response. I saw your help on [this post](https://discord.com/channels/979116623879368755/1068377326859059220) and was able to adapt your instructions. I fixed the issue by deleting the asset in question. I'll put my queries here for future people to stumble on... Get into your postgres container to run SQL queries: ```sh docker exec -it immich_postgres psql -U postgres -d immich ``` Check out the missing asset in question. ``` immich=# select * from assets where "livePhotoVideoId" = '111f65b7-962e-46be-962f-b78b577c4da3'; <large output> (1 row) ``` This spit out a large output, but the part I needed was `id`: `73bf3a56-8df1-4928-9817-1efd0122d21c` Then I checked to see if the live photo video asset existed... ``` immich=# select * from assets where "id" = '111f65b7-962e-46be-962f-b78b577c4da3'; (0 rows) ``` Turns out it didn't. So I just deleted this asset ``` immich=# delete from assets where "id" = '73bf3a56-8df1-4928-9817-1efd0122d21c'; DELETE 1 ``` Restarted my stack and the migration was successful.
Author
Owner

@alextran1502 commented on GitHub (Feb 22, 2023):

Amazing! Thank you for the response!

@alextran1502 commented on GitHub (Feb 22, 2023): Amazing! Thank you for the response!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#705