PostgreSQL Error 42704: Object Does Not Exist
Troubleshoot PostgreSQL SQLSTATE 42704 by checking the current database, schema search_path, quoted names, and object definitions.
On this page
PostgreSQL SQLSTATE 42704 is undefined_object. It means a named database object required by a statement could not be found. Read the full error message to identify the object type and name; PostgreSQL lists the code in its error-code appendix.
Check the database and schema used by this connection
An object can exist in another database or schema but still be unavailable to the current connection. Check the connection context:
SELECT current_database(), current_schema(), current_setting('search_path');
For an unqualified name, PostgreSQL searches the schemas in search_path. If you know the object’s schema, qualify its name, for example app.order_status instead of order_status. See the PostgreSQL schema search path documentation.
Unquoted identifiers are folded to lowercase. If an object was created with a quoted mixed-case name, use the exact spelling and double quotes each time:
CREATE TYPE public."OrderStatus" AS ENUM ('pending', 'paid');
-- Refers to the unquoted lower-case name orderstatus, not "OrderStatus":
SELECT NULL::public.orderstatus;
-- Refers to the quoted mixed-case type:
SELECT NULL::public."OrderStatus";
For a migration that should create a type, confirm it ran in this database and schema before running statements that depend on it. Avoid rerunning CREATE TYPE blindly if the type already exists; inspect its definition first.
Look up the named object
For a user-defined type, check pg_type and its namespace:
SELECT n.nspname AS schema_name, t.typname AS type_name, t.typtype
FROM pg_type AS t
JOIN pg_namespace AS n ON n.oid = t.typnamespace
WHERE t.typname = 'order_status';
For a named table constraint, check the relation and constraint together:
SELECT conname, conrelid::regclass AS table_name, contype
FROM pg_constraint
WHERE conname = 'orders_status_check';
If the object is absent, check the intended database, schema, migration history, and spelling. If it is present in another schema, qualify the reference or adjust the role’s search_path deliberately.
Distinguish related errors
- 42704 (
undefined_object): a named database object, such as a type or constraint, could not be resolved. - 42P01 (
undefined_table): a table or other relation could not be found; see Error 42P01. - 42703 (
undefined_column): a column reference could not be resolved; see Error 42703. - 42883 (
undefined_function): no matching function signature could be resolved; see Error 42883.
For other SQLSTATE guides, browse PostgreSQL Error Troubleshooting.