Skip to content

Table not found: relation does not exist

Quick summary

Your SQL references a table name that does not exist — the database reports an unknown table or relation error.

Why this happens

  • The table name is misspelled or uses the wrong case in a case-sensitive database

  • The table was dropped or not yet created by a pending migration

  • The table is in a different schema and needs a schema prefix (schema.table)

Minimal example

✗ Broken code
await db.query('SELECT * FROM user_orders');
// Error: relation user_orders does not exist — table is user_order
✓ Fixed code
await db.query('SELECT * FROM user_order');
// Or with schema: SELECT * FROM public.user_order;

Correcting the table name to match the actual schema resolves the unknown table error.

How to diagnose

  • List tables with SHOW TABLES or query information_schema to verify the table exists

  • Check the table name spelling and the current schema search path

  • Verify that all migrations have been run and the table was created

How to fix

  • Correct the table name spelling or add the schema prefix: myschema.mytable

  • Run the pending migration that creates the table

  • Set the search_path or use fully qualified names to reference tables in other schemas

How to prevent

  • Use a schema management tool or migration system to track table creation

  • Validate table names against the schema in integration tests before deployment

Related Resources

Related Glossary

Related Lessons

← Back to language