App Finishers

Fix guide · updated 2026-11-16

Supabase "relation … does not exist" (42P01)

{"code":"42P01","details":null,"hint":null,"message":"relation \"public.orders\" does not exist"}

A Supabase call fails with "relation "public.orders" does not exist", code 42P01. Through supabase-js it comes back as HTTP 404, which looks like a missing page or function. The name in the message is a table or view that some SQL tried to read, and Postgres found nothing by that name. We reproduced every case below on Postgres 16 behind Supabase's Data API (PostgREST 13), November 2026.

What the error means

When your app asks for a table that doesn't exist, with supabase.from('orders'), the answer is a different error: "Could not find the table 'public.orders' in the schema cache" (PGRST205). So 42P01 comes from SQL that runs inside the database: a function you call with rpc(), a function a policy calls, a trigger, or a migration you run.

The table in the message isn't always the one you asked for. In our test, reading profiles failed with "relation "public.admins" does not exist": a policy on profiles called a function that read admins, and admins had been dropped.

Check the code, not just the 404: "Could not find the function" (PGRST202) is a 404 too.

When Postgres catches it

Postgres also lets you drop or rename a table that a plpgsql function uses. In our test, drop table went through, while a view on another table blocked its drop with "cannot drop table staff because other objects depend on it".

Cause 1: the table really isn't there

It was never created (a migration that didn't run, or one run on another project), or it was dropped or renamed after the function was written. If the message has the schema, like public.orders, and the check below finds nothing, this is your case.

Cause 2: search_path = '' without schema names

Supabase's database linter warns "Function Search Path Mutable" on functions that don't set a search_path, and recommends set search_path = ''. Its own docs add the catch: after that, every table in the function needs its schema. In our test, a function with set search_path = '' that read from profiles failed with "relation "profiles" does not exist", and public.profiles worked. As a SQL function, the same body was refused at creation.

set search_path = public also worked, and it also silences the warning: the linter only checks that the function sets a search path. Supabase's recommendation is still '' with full names.

Cause 3: a capital letter in the table name

A table created as "Orders", with quotes, keeps its capital. Without quotes, Postgres reads every name in lower case. In our test, a function reading from orders failed with "relation "orders" does not exist", and public."Orders" worked. From supabase-js, from('orders') got PGRST205 with the hint "Perhaps you meant the table 'public.Orders'", and from('Orders') worked.

Cause 4: the table is in another schema

A table kept out of the API in its own schema, say private.plans, has to be named with that schema. In our test, from plans failed with "relation "plans" does not exist", and from private.plans worked.

The one-minute check

Look for the name in every schema, in any capitalization, in the SQL Editor:

select table_schema, table_name, table_type
from information_schema.tables
where lower(table_name) like '%orders%';

Then find the functions that mention it:

select p.oid::regprocedure as function_name
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public' and p.prosrc ilike '%orders%';

Nothing in the first list: cause 1. Found with a capital letter: cause 3. Found in another schema: cause 4. Found in public, but the function has search_path = '' and no schema in the name: cause 2.

Fix 1: name the schema in every function

Write the full name, public.orders, private.plans or public."Orders", and replace the function:

create or replace function public.order_count()
returns bigint
language plpgsql stable
set search_path = ''
as $$
begin
  return (select count(*) from public.orders);
end $$;

This also works with set search_path = '', the setting the linter asks for.

Fix 2: create the table, or follow the new name

If the table is missing, create it, or run the migration that creates it. If it was renamed, update every function that still uses the old name. The second query above lists them.

Fix 3: migrations in order

Create a table before the functions, views and policies that read it. Since SQL functions, views and policies are checked at creation, a migration that creates them first fails with this error and stops.

If an AI tool built your app

Give your AI tool this prompt, with the name from your error:

My Supabase app fails with relation "public.orders" does not exist (42P01). Find every database function, trigger function, view and RLS policy that reads this table. Check that the table exists, with this exact name and capitalization, and in which schema. Then write a migration that uses the full schema-qualified name everywhere (public.orders), keeps set search_path = '' on functions that have it, and creates any missing table before the objects that read it. Show me the SQL before running it.

Not quite your error?

Still stuck?

Call the function in the SQL Editor, for example select public.order_count();. The error there ends with a CONTEXT line, such as "PL/pgSQL function order_count() line 1 at RETURN", which names the function and the line that read the missing table.

Other Supabase problems? See Supabase fixes.