[GH-ISSUE #245] SqliteError: FOREIGN KEY constraint failed when trying to add bookmark #170

Closed
opened 2026-03-02 11:47:16 +03:00 by kerem · 11 comments
Owner

Originally created by @arminus on GitHub (Jun 20, 2024).
Original GitHub issue: https://github.com/karakeep-app/karakeep/issues/245

Tried to set this up with docker compose on a Pi4, but I'm getting this when trying to add a bookmark:

SqliteError: FOREIGN KEY constraint failed
    at w.values (/app/apps/web/.next/server/chunks/917.js:51:42087)
    ... 3 lines matching cause stack trace ...
    at QueryPromise.then (/app/apps/web/.next/server/chunks/917.js:51:45895) {
  code: 'INTERNAL_SERVER_ERROR',
  name: 'TRPCError',
  [cause]: SqliteError: FOREIGN KEY constraint failed
      at w.values (/app/apps/web/.next/server/chunks/917.js:51:42087)
      at w.all (/app/apps/web/.next/server/chunks/917.js:51:41676)
      at QueryPromise.all (/app/apps/web/.next/server/chunks/917.js:51:70800)
      at QueryPromise.execute (/app/apps/web/.next/server/chunks/917.js:51:70923)
      at QueryPromise.then (/app/apps/web/.next/server/chunks/917.js:51:45895) {
    code: 'SQLITE_CONSTRAINT_FOREIGNKEY'
  }
}

a data/db.db is created and looks "sane" (i.e. it has some tables)

Here's my docker-compose.yml:

version: "3"
services:
  web:
    image: ghcr.io/hoarder-app/hoarder-web:${HOARDER_VERSION:-release}
    restart: unless-stopped
    volumes:
      - ./data:/data
    ports:
      - 3078:3000
    env_file:
      - .env
    environment:
      REDIS_HOST: redis
      MEILI_ADDR: http://meilisearch:7700
      DATA_DIR: /data
  redis:
    image: redis:7.2-alpine
    restart: unless-stopped
    volumes:
      - ./redis:/data
  chrome:
    image: gcr.io/zenika-hub/alpine-chrome:123
    restart: unless-stopped
    command:
      - --no-sandbox
      - --disable-gpu
      - --disable-dev-shm-usage
      - --remote-debugging-address=0.0.0.0
      - --remote-debugging-port=9222
      - --hide-scrollbars
  meilisearch:
    image: getmeili/meilisearch:v1.6
    restart: unless-stopped
    env_file:
      - .env
    environment:
      MEILI_NO_ANALYTICS: "true"
    volumes:
      - ./meilisearch:/meili_data
  workers:
    image: ghcr.io/hoarder-app/hoarder-workers:${HOARDER_VERSION:-release}
    restart: unless-stopped
    volumes:
      - ./data:/data
    env_file:
      - .env
    environment:
      REDIS_HOST: redis
      MEILI_ADDR: http://meilisearch:7700
      BROWSER_WEB_URL: http://chrome:9222
      DATA_DIR: /data
      # OPENAI_API_KEY: ...
    depends_on:
      - web

env HOARDER_VERSION=release

Originally created by @arminus on GitHub (Jun 20, 2024). Original GitHub issue: https://github.com/karakeep-app/karakeep/issues/245 Tried to set this up with docker compose on a Pi4, but I'm getting this when trying to add a bookmark: ``` SqliteError: FOREIGN KEY constraint failed at w.values (/app/apps/web/.next/server/chunks/917.js:51:42087) ... 3 lines matching cause stack trace ... at QueryPromise.then (/app/apps/web/.next/server/chunks/917.js:51:45895) { code: 'INTERNAL_SERVER_ERROR', name: 'TRPCError', [cause]: SqliteError: FOREIGN KEY constraint failed at w.values (/app/apps/web/.next/server/chunks/917.js:51:42087) at w.all (/app/apps/web/.next/server/chunks/917.js:51:41676) at QueryPromise.all (/app/apps/web/.next/server/chunks/917.js:51:70800) at QueryPromise.execute (/app/apps/web/.next/server/chunks/917.js:51:70923) at QueryPromise.then (/app/apps/web/.next/server/chunks/917.js:51:45895) { code: 'SQLITE_CONSTRAINT_FOREIGNKEY' } } ``` a data/db.db is created and looks "sane" (i.e. it has some tables) Here's my docker-compose.yml: ``` version: "3" services: web: image: ghcr.io/hoarder-app/hoarder-web:${HOARDER_VERSION:-release} restart: unless-stopped volumes: - ./data:/data ports: - 3078:3000 env_file: - .env environment: REDIS_HOST: redis MEILI_ADDR: http://meilisearch:7700 DATA_DIR: /data redis: image: redis:7.2-alpine restart: unless-stopped volumes: - ./redis:/data chrome: image: gcr.io/zenika-hub/alpine-chrome:123 restart: unless-stopped command: - --no-sandbox - --disable-gpu - --disable-dev-shm-usage - --remote-debugging-address=0.0.0.0 - --remote-debugging-port=9222 - --hide-scrollbars meilisearch: image: getmeili/meilisearch:v1.6 restart: unless-stopped env_file: - .env environment: MEILI_NO_ANALYTICS: "true" volumes: - ./meilisearch:/meili_data workers: image: ghcr.io/hoarder-app/hoarder-workers:${HOARDER_VERSION:-release} restart: unless-stopped volumes: - ./data:/data env_file: - .env environment: REDIS_HOST: redis MEILI_ADDR: http://meilisearch:7700 BROWSER_WEB_URL: http://chrome:9222 DATA_DIR: /data # OPENAI_API_KEY: ... depends_on: - web ``` env HOARDER_VERSION=release
kerem 2026-03-02 11:47:16 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@MohamedBassem commented on GitHub (Jun 22, 2024):

That's weird. Did you try wiping the database file and restarting the web container?

<!-- gh-comment-id:2184039137 --> @MohamedBassem commented on GitHub (Jun 22, 2024): That's weird. Did you try wiping the database file and restarting the web container?
Author
Owner

@arminus commented on GitHub (Jun 22, 2024):

Just did that, error is gone. Strange.

<!-- gh-comment-id:2184044515 --> @arminus commented on GitHub (Jun 22, 2024): Just did that, error is gone. Strange.
Author
Owner

@MohamedBassem commented on GitHub (Jun 22, 2024):

Yeah, first time seeing this as well.

<!-- gh-comment-id:2184044724 --> @MohamedBassem commented on GitHub (Jun 22, 2024): Yeah, first time seeing this as well.
Author
Owner

@ItsNoted commented on GitHub (Jun 25, 2024):

Getting the same error. Even after deleting the DB file and restarting. All I wanted to do was update the app and it had to break. Now it's gone lol.

Even trying a fresh install it wont budge.

<!-- gh-comment-id:2189018231 --> @ItsNoted commented on GitHub (Jun 25, 2024): Getting the same error. Even after deleting the DB file and restarting. All I wanted to do was update the app and it had to break. Now it's gone lol. Even trying a fresh install it wont budge.
Author
Owner

@ItsNoted commented on GitHub (Jun 25, 2024):

Strange. I spun up a new container and reinstalled it and it works now. It must have been saving data that was not mounted somewhere. That was weird.

<!-- gh-comment-id:2189108846 --> @ItsNoted commented on GitHub (Jun 25, 2024): Strange. I spun up a new container and reinstalled it and it works now. It must have been saving data that was not mounted somewhere. That was weird.
Author
Owner

@lnicola commented on GitHub (Jul 29, 2024):

I think one way to reproduce this is by deleting the containers and volumes, then submitting a new bookmark without logging out and signing up again.

<!-- gh-comment-id:2255575058 --> @lnicola commented on GitHub (Jul 29, 2024): I think one way to reproduce this is by deleting the containers and volumes, then submitting a new bookmark without logging out and signing up again.
Author
Owner

@MaxPowers1337 commented on GitHub (Sep 24, 2024):

I think one way to reproduce this is by deleting the containers and volumes, then submitting a new bookmark without logging out and signing up again.

Jeah, thats what i think, too. I wiped all container and all data. Browser stayed logged in. I was able to navigate as if the session was there yet/already. I was wondering where the fresh install got my account from. Then i logged out.. and wasnt able to login again.

so somehow the "fresh" install recognize my session without having an corresponding local account?

<!-- gh-comment-id:2371655784 --> @MaxPowers1337 commented on GitHub (Sep 24, 2024): > I think one way to reproduce this is by deleting the containers and volumes, then submitting a new bookmark without logging out and signing up again. Jeah, thats what i think, too. I wiped all container and all data. Browser stayed logged in. I was able to navigate as if the session was there yet/already. I was wondering where the fresh install got my account from. Then i logged out.. and wasnt able to login again. so somehow the "fresh" install recognize my session without having an corresponding local account?
Author
Owner

@lnicola commented on GitHub (Sep 24, 2024):

so somehow the "fresh" install recognize my session without having an corresponding local account?

Yeah, I wouldn't really worry about it. I forgot what Hoarder is doing (EDIT: it's a big cookie), but these days it's not uncommon to put the session data into an encrypted cookie instead of keeping it in the memory or a database.

<!-- gh-comment-id:2371662628 --> @lnicola commented on GitHub (Sep 24, 2024): > so somehow the "fresh" install recognize my session without having an corresponding local account? Yeah, I wouldn't really worry about it. I ~~forgot what Hoarder is doing~~ (EDIT: it's a big cookie), but these days it's not uncommon to put the session data into an encrypted cookie instead of keeping it in the memory or a database.
Author
Owner

@MohamedBassem commented on GitHub (Sep 29, 2024):

@MaxPowers1337 @lnicola I've seen multiple people getting confused by this so far. It's indeed as @lnicola explained. Hoarder uses something called "JWT" which holds the user information in the browser, and when you wipe the database, your user no longer exists and you start hitting this issue. I think I can add a way to validate the JWT from time to time so that you get logged out when your JWT is no longer valid.

<!-- gh-comment-id:2381055022 --> @MohamedBassem commented on GitHub (Sep 29, 2024): @MaxPowers1337 @lnicola I've seen multiple people getting confused by this so far. It's indeed as @lnicola explained. Hoarder uses something called "JWT" which holds the user information in the browser, and when you wipe the database, your user no longer exists and you start hitting this issue. I think I can add a way to validate the JWT from time to time so that you get logged out when your JWT is no longer valid.
Author
Owner

@WolforOwl commented on GitHub (Oct 4, 2024):

@MaxPowers1337 @lnicola I've seen multiple people getting confused by this so far. It's indeed as @lnicola explained. Hoarder uses something called "JWT" which holds the user information in the browser, and when you wipe the database, your user no longer exists and you start hitting this issue. I think I can add a way to validate the JWT from time to time so that you get logged out when your JWT is no longer valid.

Thanks. this helped me. When I get this error (Foreign key..), I log off and create a new user. Error gone.

<!-- gh-comment-id:2394699572 --> @WolforOwl commented on GitHub (Oct 4, 2024): > @MaxPowers1337 @lnicola I've seen multiple people getting confused by this so far. It's indeed as @lnicola explained. Hoarder uses something called "JWT" which holds the user information in the browser, and when you wipe the database, your user no longer exists and you start hitting this issue. I think I can add a way to validate the JWT from time to time so that you get logged out when your JWT is no longer valid. Thanks. this helped me. When I get this error (Foreign key..), I log off and create a new user. Error gone.
Author
Owner

@MohamedBassem commented on GitHub (Oct 5, 2024):

I sent github.com/hoarder-app/hoarder@f1c956a361 which should eliminate this confusion. If your account gets deleted, you'll be automatically get signed out starting from the next release.

<!-- gh-comment-id:2395122562 --> @MohamedBassem commented on GitHub (Oct 5, 2024): I sent https://github.com/hoarder-app/hoarder/commit/f1c956a361539592d00836488181b69218798600 which should eliminate this confusion. If your account gets deleted, you'll be automatically get signed out starting from the next release.
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/karakeep#170
No description provided.