DEV Community

Ahmed Hassan Yaseen
Ahmed Hassan Yaseen

Posted on AI-assisted

Fix Supabase "Could not find the table in the schema cache" (PGRST205)

You add a table, or your AI builder adds one for you, and the screen that uses it fails. The browser console shows this:

{
  "code": "PGRST205",
  "details": null,
  "hint": null,
  "message": "Could not find the table 'public.invoices' in the schema cache"
}
Enter fullscreen mode Exit fullscreen mode

The table may be right there in the Table Editor. The message isn't about what your database holds; it's about what Supabase's API thinks exists. Below is how I work out which of four causes it is, and how to fix the related PGRST200 error you get on joins.

It's based on PostgREST's error reference and schema cache docs, Supabase's troubleshooting articles on the schema cache and its custom schemas guide, all read on 3 December 2026. I also reproduced each case against a local PostgREST 16.6 to check the exact responses.

What the message actually means

Your app doesn't talk to Postgres directly. supabase.from('invoices') becomes a request to the Data API, which is PostgREST. To avoid running expensive catalog queries on every request, PostgREST keeps a schema cache: its own copy of which tables, columns, functions and foreign keys exist.

PGRST205 means the table named in the request isn't in that copy. The PostgREST error reference lists it under schema cache errors with HTTP 404: "Caused when the table specified in the URI is not found." It's a fairly new code. PostgREST's changelog for 13.0.0 (8 May 2025) says "Querying non-existent table now returns PGRST205 error instead of empty json", so older posts about this problem show different errors.

That gives four questions, in the order I ask them:

  1. Does the table exist in the project my app is calling?
  2. Is the name exactly right, capitals included?
  3. Is it in a schema the API serves, and is the app asking for that schema?
  4. Is the cache just out of date?

Step 1: read the whole error

The hint field often answers the question for you. Log all of it:

const { data, error } = await supabase.from('invoices').select('*')

if (error) {
  console.error(error.code, error.message, error.hint)
}
Enter fullscreen mode Exit fullscreen mode

With a typo or a case mismatch, PostgREST suggests the closest table it knows, for example "hint": "Perhaps you meant the table 'public.invoices'". Don't build anything on that hint: the changelog's unreleased section removes it from PGRST205 to stop leaking table names. A null hint tells you nothing either way.

Also notice the schema in the message. 'public.orders' means PostgREST looked in public, even if your table lives somewhere else.

Step 2: check the table exists in this project

Open the Supabase project your live app actually uses. Compare the project URL in the dashboard with VITE_SUPABASE_URL (or whatever your app reads). It's common to have a dev and a production project, and to have created the table in the other one. Then run this in the SQL Editor:

select table_schema, table_name
from information_schema.tables
where table_name ilike '%invoice%';
Enter fullscreen mode Exit fullscreen mode

No row means the table was never created here. In AI-built apps this is the cause I check first. Lovable's Supabase integration docs say schema changes run as reviewed migrations: "Lovable writes the SQL, shows it to you, and asks for your approval in the project chat before running it." If an approval card is still sitting in the chat, the app code is ahead of the database.

If you manage migrations with the Supabase CLI, compare the files with what the linked project has applied, then push the missing ones. In the current CLI, both commands target the local database unless you pass --remote (migration list, db push):

supabase migration list --remote
supabase db push --remote
Enter fullscreen mode Exit fullscreen mode

Step 3: match the name exactly

Postgres's documentation on identifiers puts it in one line: "Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case."

So a table created as create table "Customers" is not customers. When I reproduced this on a local PostgREST, .from('customers') returned PGRST205 with the hint Perhaps you meant the table 'public.Customers', and .from('Customers') worked. Either call it with the exact name, or rename the table to lower case and update the code:

alter table public."Customers" rename to customers;
Enter fullscreen mode Exit fullscreen mode

Renaming breaks anything else that uses the old name, so search your code for it first.

Step 4: check the schema

By default, Supabase exposes the public schema. For anything else, the custom schemas guide has two steps: add the schema to "Exposed schemas" in the API settings, then grant the API roles access to it (its SQL starts with GRANT USAGE ON SCHEMA myschema TO anon, authenticated, service_role;).

Even then, the request has to name the schema. Supabase's article on PostgREST not recognizing objects in a schema explains that when several schemas are exposed, "the first entry in the list is treated as the default", and unqualified names are looked up only there. That's the 'public.orders' case from step 1. Ask for the schema in the client or per query:

const { data, error } = await supabase.schema('billing').from('orders').select('*')
Enter fullscreen mode Exit fullscreen mode

If the schema isn't exposed at all, you get a different code, PGRST106, which is your sign to fix the settings rather than the query.

Step 5: reload the schema cache

If the table exists, the name matches and the schema is right, the cache is stale. PostgREST's docs say the cache goes stale "when you make changes to the database" and has to be reloaded. Supabase's refresh article gives the command to run in the SQL Editor:

NOTIFY pgrst, 'reload schema';
Enter fullscreen mode Exit fullscreen mode

You should see Success. No rows returned. Then retry the request.

If the error survives a reload, Supabase has a second article, PostgREST not recognizing new columns or functions, for when reload signals don't arrive. Look in the API logs for Failed listening for database notifications on the "pgrst" channel; its fix is SELECT pg_notification_queue_usage();.

When the error changes to "permission denied"

This one catches people out. In my local test, a new table with no grants first returned PGRST205 (stale cache). After the reload it returned 42501 permission denied for table payments. That's progress, not a new bug: PostgREST now sees the table, and Postgres refuses the role. Supabase's guide to securing the Data API says "A table isn't reachable through the Data API unless you have granted a role privileges on it", so the next step is a grant plus Row Level Security, not another reload.

The relationship version: PGRST200

Joins hit the same cache. If you embed a related table, select('id, invoices(id)'), and get this:

Could not find a relationship between 'payments' and 'invoices' in the schema cache
Enter fullscreen mode Exit fullscreen mode

that's PGRST200. The error reference says it's "Caused by stale foreign key relationships, otherwise any of the embedding resources or the relationship itself may not exist in the database." PostgREST builds joins from foreign keys, and its resource embedding docs add: "Whenever foreign keys change you must do Schema Cache Reloading for this feature to work."

In practice there are three cases. There's no foreign key at all (an AI tool added an invoice_id column but no constraint): add one, then reload:

alter table public.payments
  add constraint payments_invoice_id_fkey
  foreign key (invoice_id) references public.invoices (id);

NOTIFY pgrst, 'reload schema';
Enter fullscreen mode Exit fullscreen mode

The key exists but was added after the last reload: reload. Or the name in the select is wrong: the details field shows what it searched for, and the hint may suggest the right name (Perhaps you meant 'invoices' instead of 'invoice').

Prove it works

  1. Run the exact query from the app and confirm it returns rows, or an empty list, not an error.
  2. Sign in as a normal user and repeat it, so a missing grant or policy shows up now, not after launch.
  3. Make the next migration end with NOTIFY pgrst, 'reload schema';, so the API never lags behind it.

If the error turned into "permission denied" after the reload, I wrote that fix up here: Fix "permission denied for table" in Supabase. And if your AI tool wrote most of your migrations and you'd like a second look at them, the free AI app audit reports findings with the file and line.

I wrote this with AI assistance and reviewed it myself.

Top comments (0)