keycloak: ERROR: relation "migration_model" does not exist

Describe the bug

I’m not 100% sure if this is a bug or a missing configuration from my side. I can’t get the latest Docker image quay.io/keycloak/keycloak:17.0.0 up and running. The start always fails with the follwoing log messages:

2022-02-15 19:54:42,453 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (main) SQL Error: 0, SQLState: 42P01
2022-02-15 19:54:42,453 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (main) ERROR: relation "migration_model" does not exist
  Position: 121
2022-02-15 19:54:42,500 INFO  [org.infinispan.CLUSTER] (main) ISPN000080: Disconnecting JGroups channel `ISPN`
2022-02-15 19:54:42,555 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (production) mode
2022-02-15 19:54:42,555 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2022-02-15 19:54:42,555 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: could not extract ResultSet
2022-02-15 19:54:42,556 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: ERROR: relation "migration_model" does not exist
  Position: 121

Anyone experiencing the same issue? The configuration was working with the jboss/keycloak:16.1.0 image. I also tried to delete and re-create an empty database schema. But no luck either.

Version

17.0.0

Expected behavior

successfull start.

Actual behavior

ERROR: ERROR: relation "migration_model" does not exist

How to Reproduce?

# docker-compose.yml
version: "3.6"
services:
  ## Keycloak IAM Authentication Provider
  authentication-provider:
    image: quay.io/keycloak/keycloak:17.0.0
    command: "start --auto-build"
    ports:
      - "9001:8080"
    restart: unless-stopped
    environment:
      ## Host settings
      KC_HOSTNAME: keycloak
      ## Database settings
      KC_DB: postgres
      KC_DB_URL: jdbc:postgresql://${PG_HOST}:${PG_PORT}/${PG_DB}
      KC_DB_SCHEMA: ${KEYCLOAK_SCHEMA}
      KC_DB_USERNAME: ${PG_USER}
      KC_DB_PASSWORD: ${PG_PASSWORD}
      ## Admin User settings
      KEYCLOAK_USER: ${KEYCLOAK_USER}
      KEYCLOAK_PASSWORD: ${KEYCLOAK_PASSWORD}
      ## Proxy settings
      KC_PROXY: edge

### Anything else?

_No response_

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 25 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Same issue for me but only when i try to connect to postgresql on Azure , locally works fine. I Resolved it (workaround) by specifying schema name inside KC_DB_SCHEMA and also in KC_DB_URL

ENV KC_DB_URL=jdbc:postgresql://[db_addr]:[db_port]/[db_name]?currentSchema=[db_schema]

The issue miraculously disappeared.

I’m seeing this in version 18, but Keycloak does start. Is this expected?

postgres_1  | 2022-07-22 20:33:19.521 UTC [69] ERROR:  relation "migration_model" does not exist at character 25
postgres_1  | 2022-07-22 20:33:19.521 UTC [69] STATEMENT:  SELECT ID, VERSION FROM MIGRATION_MODEL ORDER BY UPDATE_TIME DESC
postgres_1  | 2022-07-22 20:33:20.604 UTC [69] ERROR:  relation "public.databasechangelog" does not exist at character 22
postgres_1  | 2022-07-22 20:33:20.604 UTC [69] STATEMENT:  SELECT COUNT(*) FROM public.databasechangelog
postgres_1  | 2022-07-22 20:33:21.358 UTC [70] ERROR:  relation "public.databasechangeloglock" does not exist at character 22
postgres_1  | 2022-07-22 20:33:21.358 UTC [70] STATEMENT:  SELECT COUNT(*) FROM public.databasechangeloglock
postgres_1  | 2022-07-22 20:33:21.399 UTC [69] ERROR:  relation "public.databasechangelog" does not exist at character 22
postgres_1  | 2022-07-22 20:33:21.399 UTC [69] STATEMENT:  SELECT COUNT(*) FROM public.databasechangelog

Hi, your postgresql database is missing a schema search path. Use this sql statement:

postgres=# ALTER ROLE myUser SET search_path TO mySchema,public;

This worked for me.

Just encountered the same error after I changed from --db-url to using separate env variables on 17.0.0 -> 17.0.0.

I kept this workaround since keycloak-x16:

KC_DB_URL_HOST=
KC_DB_URL_DATABASE=
KC_DB_SCHEMA=
 kc.sh start --db-url="jdbc:postgresql://${KC_DB_URL_HOST}/${KC_DB_URL_DATABASE}?currentSchema=${KC_DB_SCHEMA}"

It works because kc.sh in docker evaluates variables

This issue should have been fixed, I think? https://github.com/keycloak/keycloak/issues/9398 https://github.com/keycloak/keycloak/issues/9328