[GH-ISSUE #57] Foreign key constraint error on startup #44

Closed
opened 2026-02-26 21:34:10 +03:00 by kerem · 3 comments
Owner

Originally created by @coopbri on GitHub (Oct 16, 2024).
Original GitHub issue: https://github.com/eduardolat/pgbackweb/issues/57

When running this in Docker against a Postgres v16.3 database, I get the following error in the logs (crashing the container):

2024/10/16 12:52:30 goose run: ERROR 20240720055720_add_sessions_table.sql: failed to run SQL migration: failed to execute SQL query "CREATE TABLE IF NOT EXISTS sessions (\n  id UUID NOT NULL DEFAULT uuid_generate_v4() PRIMARY KEY,\n  user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,\n  token BYTEA NOT NULL,\n  ip TEXT NOT NULL,\n  user_agent TEXT NOT NULL,\n  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()\n);\nCREATE INDEX IF NOT EXISTS\nidx_sessions_user_id ON sessions(user_id);": ERROR: foreign key constraint "sessions_user_id_fkey" cannot be implemented (SQLSTATE 42804)
  • PG Back Web image tags tested: latest, 0.3.0
  • Environment: PBW_ENCRYPTION_KEY set to secret string, PBW_POSTGRES_CONN_STRING set to database URL with ?sslmode=disable appended
Originally created by @coopbri on GitHub (Oct 16, 2024). Original GitHub issue: https://github.com/eduardolat/pgbackweb/issues/57 When running this in Docker against a Postgres v16.3 database, I get the following error in the logs (crashing the container): ``` 2024/10/16 12:52:30 goose run: ERROR 20240720055720_add_sessions_table.sql: failed to run SQL migration: failed to execute SQL query "CREATE TABLE IF NOT EXISTS sessions (\n id UUID NOT NULL DEFAULT uuid_generate_v4() PRIMARY KEY,\n user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,\n token BYTEA NOT NULL,\n ip TEXT NOT NULL,\n user_agent TEXT NOT NULL,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()\n);\nCREATE INDEX IF NOT EXISTS\nidx_sessions_user_id ON sessions(user_id);": ERROR: foreign key constraint "sessions_user_id_fkey" cannot be implemented (SQLSTATE 42804) ``` - PG Back Web image tags tested: `latest`, `0.3.0` - Environment: `PBW_ENCRYPTION_KEY` set to secret string, `PBW_POSTGRES_CONN_STRING` set to database URL with `?sslmode=disable` appended
kerem closed this issue 2026-02-26 21:34:10 +03:00
Author
Owner

@eduardolat commented on GitHub (Oct 17, 2024):

Are you using an empty DB for pgbackweb?

https://github.com/eduardolat/pgbackweb/issues/48
https://github.com/eduardolat/pgbackweb/issues/4

<!-- gh-comment-id:2420304919 --> @eduardolat commented on GitHub (Oct 17, 2024): Are you using an empty DB for pgbackweb? https://github.com/eduardolat/pgbackweb/issues/48 https://github.com/eduardolat/pgbackweb/issues/4
Author
Owner

@coopbri commented on GitHub (Oct 17, 2024):

No, I was not aware it required it's own postgres database, but that makes perfect sense now that I'm thinking about it! Thanks @eduardolat, silly mistake on my part.

<!-- gh-comment-id:2420412895 --> @coopbri commented on GitHub (Oct 17, 2024): No, I was not aware it required it's own postgres database, but that makes perfect sense now that I'm thinking about it! Thanks @eduardolat, silly mistake on my part.
Author
Owner

@eduardolat commented on GitHub (Oct 17, 2024):

@coopbri No worries my friend

<!-- gh-comment-id:2420696637 --> @eduardolat commented on GitHub (Oct 17, 2024): @coopbri No worries my friend
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/pgbackweb#44
No description provided.