Skip to content
ERROR: relation '...' does not exist

ERROR: relation '...' does not exist

DodaTech 2 min read

PostgreSQL “ERROR: relation ‘…’ does not exist” means the database could not find a table, view, or other relation with the given name. This is usually a schema search path issue or the relation genuinely does not exist.

What It Means

PostgreSQL looks for relations in the schemas listed in the search_path setting. If the table exists in a schema not included in the search path, or if the table does not exist at all, this error is raised.

Why It Happens

  • The table is in a schema (e.g., public) but the search path does not include it.
  • The table name is unquoted and case sensitivity causes a mismatch.
  • The table was not created or was dropped by a migration.
  • You connected to the wrong database.
  • The table was created in a different schema than expected.

How to Fix It

1. Check the current search path

SHOW search_path;

Default value is "$user", public. If your table is in a different schema, you must qualify the name.

2. List relations in the current database

\dt
\dt schema_name.*

If the relation is a view, use \dv or \d+.

3. Qualify the table with its schema

-- Wrong (schema missing)
SELECT * FROM users;

-- Correct
SELECT * FROM public.users;
SELECT * FROM app_schema.users;

4. Change the search path

SET search_path TO app_schema, public;

To make it permanent for a user:

ALTER ROLE myuser SET search_path TO app_schema, public;

5. Create the missing relation

CREATE TABLE public.users (
    id SERIAL PRIMARY KEY,
    email TEXT NOT NULL UNIQUE
);

Re-run failed migrations:

psql -U myuser -d mydb -f migrations/001_create_users.sql

6. Check for case sensitivity

PostgreSQL folds unquoted identifiers to lowercase. If the table was created with quotes, you must use quotes:

-- Created as "Users" (with quotes)
SELECT * FROM "Users"; -- Correct
SELECT * FROM Users;   -- Wrong (looks for "users")

FAQ

How do I see all schemas in my database?
Run \dn in psql or SELECT schema_name FROM information_schema.schemata; to list every schema in the database.
What does 'relation does not exist' mean for a view?
The same rules apply — views are relations in PostgreSQL. Check with \dv or query pg_class with relkind = 'v'. Qualify the view name with its schema if needed.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro