ERROR: relation does not exist for a table that is there
ERROR: relation "users" does not existShort answer
The name you typed does not resolve to the table you see. The usual reasons are a table created with a quoted mixed-case name, a table in a schema that is not on search_path, or a connection to a different database. Check with \dt and \conninfo.
Fix it fast
1Find out which cause you have
Confirm which database and user you are connected to, then list tables across all schemas matching the name.
\conninfo \dt *.*users*2Match what you see, then jump to its fix
- 1
\dt shows "Users" with a capital letterThe table was created with a quoted, mixed-case nameFix - 2
\dt *.* shows the table under a schema other than publicThe table is in a schema that is not on search_pathFix - 3
\dt returns no relations, or different ones than your tool showsYou are connected to a different databaseFix
- 1
What does the error look like?
ERROR: relation "users" does not existLINE 1: SELECT * FROM users;
Cause 1 of 3
The table was created with a quoted, mixed-case name
1Check
Unquoted names fold to lower case, so Users is read as users. A name made with double quotes keeps its case and must always be quoted.
SELECT schemaname, tablename FROM pg_tables WHERE lower(tablename) = 'users';2Fix
Quote the name exactly in queries, or rename the table to lower case once.
SELECT * FROM "Users";
-- or, once
ALTER TABLE "Users" RENAME TO users;3Verify
The unquoted query works.
SELECT count(*) FROM users;Confirmed by postgresql.org
Cause 2 of 3
The table is in a schema that is not on search_path
1Check
An unqualified name is looked up only in the schemas listed in search_path, which defaults to "$user", public.
SHOW search_path;
SELECT schemaname, tablename FROM pg_tables WHERE tablename = 'users';2Fix
Qualify the name, or add the schema to search_path for the session or the role.
SELECT * FROM app.users;
-- or
SET search_path TO app, public;
-- or persist for a role
ALTER ROLE appuser SET search_path TO app, public;3Verify
Unqualified queries resolve.
SELECT count(*) FROM users;Confirmed by postgresql.org
Cause 3 of 3
You are connected to a different database
1Check
Tables belong to one database; psql defaults the database name to the user name if you give none.
SELECT current_database(), current_user;
\l2Fix
Connect to the database that holds the table.
psql -U appuser -d appdb3Verify
The table is listed.
\dtConfirmed by postgresql.org
How do I stop it coming back?
- Create tables with unquoted lower_snake_case names.
- Set search_path per role instead of hoping the session default fits.
- Put the database name in the connection string, never rely on defaults.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Databases
ERROR: column does not exist, though you can see it in the table
ERROR: column "active" does not exist
The parser reads your column name differently from how it was stored.
3 causes, each with a fixDatabases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
DBeaver cannot download the PostgreSQL driver from Maven
The PostgreSQL driver files are missing and the download does not complete
DBeaver downloads the PostgreSQL JDBC driver from a Maven repository the first time you connect.
3 causes, each with a fixDatabases
python manage.py migrate finishes but the tables for my app are missing
relation "myapp_book" does not exist
migrate only applies migration files that exist.
3 causes, each with a fixDatabases
Django save fails on PostgreSQL: null value in a column violates a not-null constraint
django.db.utils.IntegrityError: null value in column "price" of relation "shop_product" violates not-null constraint
A model field is NOT NULL in the database unless it has null=True.
3 causes, each with a fixDatabases
Django migration on PostgreSQL stops with 'pending trigger events'
django.db.utils.OperationalError: cannot ALTER TABLE "mytable" because it has pending trigger events
PostgreSQL runs a Django migration in one transaction.
2 causes, each with a fix