relation "users" does not exist
This skill fixes the Postgres error relation does not exist when using Drizzle ORM. Use it when Drizzle queries fail because the table was never created, migrations did not run, or the schema name is wrong. It covers drizzle-kit push, migrate, and schema naming.
TL;DR
relation "users" does not exist means Postgres has no such table - your Drizzle schema was never applied to this database. Run the migration (drizzle-kit migrate) or push the schema (drizzle-kit push), and make sure you are connected to the right database.
The error
PostgresError: relation "users" does not existFix it
- Confirm you are on the right database. Print the connection string's database name (redacted) and compare with where you think the tables are. Wrong-database is the top cause.
- Expected: the connected database is the one you migrated.
- Apply the schema. For drizzle-kit:
npx drizzle-kit pushor with migrations:
npx drizzle-kit migrate- Expected: tables created, the query succeeds.
- Check the schema name. If your tables live in a non-public schema, Drizzle needs
pgSchema("myschema", ...)and the database role needs USAGE on it. Unqualifiedusersresolves to the search_path, usually public.
- Expected: qualified or search_path-correct table references.
- Check table-name casing. Drizzle lowercases unquoted names; a table created as
"Users"(quoted) is a different relation fromusers. Keep names lowercase or quote consistently.
- Expected: the relation name matches exactly.
When to use
- relation does not exist on a table Drizzle defines.
- Fresh database, new environment, or after a database reset.
When NOT to use
- column does not exist - the table is there, a column is missing (schema drift).
- Auth/connection errors - the query never reached Postgres.
Compatibility
- Drizzle ORM with drizzle-kit, PostgreSQL.
Root cause
Drizzle builds SQL from your TypeScript schema but does not create tables at runtime. If migrations/push never ran against the connected database, Postgres reports the missing relation.
Edge cases
drizzle-kit pushis for prototyping; use versionedmigratein production.- Multiple schemas:
pgTablewithoutpgSchemaalways targets the search_path default.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.