twenty icon indicating copy to clipboard operation
twenty copied to clipboard

error: schema "core" does not exist

Open Nicj228 opened this issue 6 months ago • 3 comments

Error on docker-compose instalation : query failed: SELECT "KeyValuePair"."id" AS "KeyValuePair_id",

I run yarn database:migrate:prod manualy and get the error : " schema "core" does not exist "

Nicj228 avatar May 23 '25 12:05 Nicj228

The correct esoteric incantation you need to start the app is:

yarn database:init:prod
clickhouse:migrate:prod
node dist/src/main

This first runs packages\twenty-server\scripts\setup-db.ts, which ensures the required schemas exist, then it runs the migrations.

inkysquid avatar Jun 03 '25 15:06 inkysquid

What incantations should be done for docker compose setups?

huksley avatar Jun 25 '25 11:06 huksley

I think I solved that, in my case, I was running server and worker containers using database name "postgres", which is automatically created by postgres container.

While TwentyCRM wants to have their own db, which is in the current docker compose setup called "default", and it expects to create it on the first start.

In that case, it run the migration scripts for core schema and other stuff.

But if the db exists, it silently expects everything to have already been run.

huksley avatar Jun 25 '25 12:06 huksley

This issue may be related to #12936

mateusztylec avatar Jul 01 '25 10:07 mateusztylec

I was having the same error pointed here.

As @huksley pointed out (thank you for finding this), issue is with an existing database. I was using the "postgres" image, and that creates an empty database on startup (checked via psql inside the pod).

From the chart db configuration:

      containers:
      - name: postgres
        image: {{ .Values.db.image }}  # postgres:16
        env:
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: {{ .Release.Name }}-app-secrets
              key: PG_USER

        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ .Release.Name }}-app-secrets
              key: PG_PASSWORD

The server pod starts the "migration", but fails trying to get env variables saved in the database, since the tables do not exist in that database.

Quick fix I did was running only the database pod, drop the created table from the database and then scale back the server pod, to create the new database using the setup script.

FranciscoKnebel avatar Jul 04 '25 18:07 FranciscoKnebel

yarn database:init:prod

This did the trick for me. this appears to be a key step that should be added to the documentation for the docker compose setup.

nalcabio-tom avatar Jul 18 '25 22:07 nalcabio-tom

Closing as solved!

Bonapara avatar Jul 21 '25 12:07 Bonapara

Closing as solved!

What's the solution? Is the previously mentioned yarn command still required?

carrete avatar Jul 21 '25 13:07 carrete