“relation does not exist” in Postgres and Supabase – schema, quotes, search_path, cache

By Abheesht Tripathi · Published

ERROR: 42P01: relation "profiles" does not exist
API: {"code":"PGRST205","message":"Could not find the table 'public.profiles' in the schema cache"}

What it means

Postgres resolved the name you wrote and found no table or view by that name in the schemas it searched. The table may well exist: just not under that exact name, not in a schema on the search_path, or not in this database. Through the Supabase API the same situation shows up as PGRST205, HTTP 404.

Step 1: find where the table really is

select table_schema, table_name
from information_schema.tables
where table_name ilike '%profile%';

show search_path;

select to_regclass('public.profiles');   -- null means: no such table

Run this in the SQL Editor of the same project your app talks to. The answer points to one of the causes below.

The usual causes

  1. Different schema. The table is app.profiles, but the query says profiles and the search path is "$user", public, extensions. Qualify the name (app.profiles). From supabase-js, use supabase.schema('app').from('profiles') and add app to Exposed schemas in the API settings.
  2. Upper-case letters in quotes. A table created as "Profiles" (common with GUI tools and some ORMs) must always be written with quotes and the same case. Unquoted Profiles is folded to profiles, which doesn't exist. Renaming it to lower case saves you from this forever: alter table "Profiles" rename to profiles;
  3. A function with an empty search_path. Functions defined with set search_path = '' (the recommended secure setting) see no schemas at all, so every name inside must be qualified: public.profiles, not profiles.
  4. The migration ran somewhere else. It ran locally or on staging, not on the project in your app's URL. Compare with supabase migration list, then supabase db push to the right project.
  5. A stale API schema cache (PGRST205 only). The table exists, but the API hasn't reloaded its view of the schema yet.
  6. Migration order. Migrations run in file-name (timestamp) order. A policy, view or foreign key in 20260101_policies.sql that refers to a table created in 20260105_tables.sql works on a database where you ran things by hand, then fails on supabase db reset or a fresh branch. Rename the file so the table is created first.

Fixes

-- 1. qualify the name
select * from app.profiles;

-- 3. qualify names inside functions that pin search_path
create or replace function public.profile_count()
returns bigint
language sql
stable
set search_path = ''
as $$
  select count(*) from public.profiles;
$$;

-- 5. ask the API to reload its schema cache
notify pgrst, 'reload schema';

Not this error

How to verify

select to_regclass('public.profiles'); returns the name rather than null, the query runs in the SQL Editor, and the same call from your app returns rows or an empty list instead of PGRST205. If the SQL Editor works but the app doesn't, compare the project URL in your app's environment with the project you are looking at.

Related guides

More in Postgres errors and performance · all guides