Docker: There was an error initializing DB: "relation "credentials_entity" does not exist"

I’m trying to run n8n via docker. But I got this error:
There was an error initializing DB: “relation “credentials_entity” does not exist”

I’m new on n8n. I have tried many image versions, it seems the error only happened on version 0.167.0 and newer version.

docker run -it --rm \
        --name n8n \
        -p 5678:5678 \
        -e DB_TYPE=postgresdb \
        -e DB_POSTGRESDB_DATABASE=postgres \
        -e DB_POSTGRESDB_HOST=172.17.0.2 \
        -e DB_POSTGRESDB_PORT=5432 \
        -e DB_POSTGRESDB_USER=postgres \
        -e DB_POSTGRESDB_SCHEMA=n8n1 \
        -e DB_POSTGRESDB_PASSWORD=mysecretpassword \
        -v ~/.n8n:/home/node/.n8n \
        n8nio/n8n:0.167.0 \
        n8n start

Initializing n8n process
There was an error initializing DB: "relation "credentials_entity" does not exist"

Version 0.166.0 and earlier version can be started.

docker run -it --rm \
        --name n8n \
        -p 5678:5678 \
        -e DB_TYPE=postgresdb \
        -e DB_POSTGRESDB_DATABASE=postgres \
        -e DB_POSTGRESDB_HOST=172.17.0.2 \
        -e DB_POSTGRESDB_PORT=5432 \
        -e DB_POSTGRESDB_USER=postgres \
        -e DB_POSTGRESDB_SCHEMA=n8n1 \
        -e DB_POSTGRESDB_PASSWORD=mysecretpassword \
        -v ~/.n8n:/home/node/.n8n \
        n8nio/n8n:0.166.0 \
        n8n start

Initializing n8n process
n8n ready on 0.0.0.0, port 5678
Version: 0.166.0

Editor is now accessible via:
http://localhost:5678/

Press "o" to open in Browser.

I searched the error, but didn’t find useful info. Could you help?

Hey @woo,

Welcome to the community :raised_hands:

I take it this is an upgrade rather than a clean setup with a new database? Does it also happen on the latest release?

Hi jon,

It also happens in latest release with a new database!

Hey @woo,

I have just given it a bash on a new new image with a new database then I took another look and it looks like this could be related to a schema issue someone reported on Github as well which I have not had a chance to reproduce yet: Postgres migrations are inconsistent on alternate schema · Issue #3325 · n8n-io/n8n · GitHub

Does this look like the same thing you are seeing?

Hey @jon,

Thanks for looking into it! Yes, I think it’s the same issue.
I did another test with latest version and a new database. Here is the log:

docker run -it --rm \
        --name n8n \
        -p 5678:5678 \
        -e DB_TYPE=postgresdb \
        -e DB_POSTGRESDB_DATABASE=postgres \
        -e DB_POSTGRESDB_HOST=172.17.0.2 \
        -e DB_POSTGRESDB_PORT=5432 \
        -e DB_POSTGRESDB_USER=postgres \
        -e DB_POSTGRESDB_SCHEMA=n8n1 \
        -e DB_POSTGRESDB_PASSWORD=mysecretpassword \
        -v ~/.n8n:/home/node/.n8n \
        n8nio/n8n \
        n8n start

Initializing n8n process
query is slow: CREATE TABLE "n8n1"."migrations" ("id" SERIAL NOT NULL, "timestamp" bigint NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_b060ba0bfc658738c5d7f955381" PRIMARY KEY ("id"))
execution time: 3475
There was an error initializing DB: "relation "credentials_entity" does not exist"

Stopping n8n...

Hey @woo,

The good news then is at least we know it is when a different schema is used, I will pass this up to our core team so they can work on a fix. For now though I would say it is a case of using an older version or not using a different schema.

Hey @jon ,

I’ll use public schema for now. Thanks for your support!

1 Like