Supabase: Could not find a relationship in the schema cache
Could not find a relationship between 'posts' and 'users' in the schema cache (PGRST200, HTTP 400) means PostgREST looked for a foreign key between the two tables in your select and found none in the schema it searched. Add the foreign key (or fix the table name), name it in the query when there are several, and run notify pgrst, 'reload schema';. If the second table is users, you were embedding auth.users: point the key at a public.profiles table instead of creating a view over auth.users.
The error comes from PostgREST, the server behind supabase.from(). Embedding another table in a select, like select('*, users(*)'), is a join that PostgREST builds from a foreign key. With no foreign key to follow, it refuses before running anything.
What does "Could not find a relationship between" mean?
PostgREST keeps a cached map of your tables and the foreign keys between them. In its Error.hs the error has code PGRST200, status 400, and three parts:
const { data, error } = await supabase.from("posts").select("id, title, users(email)");
// error.code === "PGRST200"
// error.message === "Could not find a relationship between 'posts' and 'users' in the schema cache"
// error.details === "Searched for a foreign key relationship between 'posts' and 'users'
// in the schema 'public', but no matches were found."
Read details first: it names the schema PostgREST searched, which rules causes 3 and 5 below in or out at once. The hint field, when present, catches typos. PostgREST fuzzy-matches the names and suggests one, as in Perhaps you meant 'profiles' instead of 'profile'.
The causes, in the order to check them
1. There is no foreign key. A column called author_id holding user ids is not a relationship until a constraint says so. Add one:
alter table public.posts
add constraint posts_author_id_fkey
foreign key (author_id) references public.profiles (id);
2. The name in the query doesn't match. Embedding uses table names, so profile(*) won't find profiles. Check the hint, and remember that a table created with quotes ("Profiles") has a capital letter in its name.
3. The key points into another schema. This is the common one, and it has its own section below: a foreign key to auth.users doesn't make users embeddable, because auth isn't one of the schemas the API exposes.
4. There's more than one key. Two foreign keys from posts to profiles (say author_id and editor_id) give a different error, Could not embed because more than one relationship was found for 'posts' and 'profiles' (PGRST201, status 300). Name the constraint or column you want:
await supabase.from("posts").select("id, title, author:profiles!posts_author_id_fkey(display_name)");
5. The cache is stale. A foreign key added a moment ago can be missing until PostgREST reloads its map. Changes are normally picked up on their own. When one isn't, run this in the SQL Editor:
notify pgrst, 'reload schema';
If the reload doesn't help, the key isn't there, or isn't where details says PostgREST looked.
Why "posts" and "users" is different
Most Supabase tutorials point user columns at auth.users:
author_id uuid not null references auth.users (id)
That's a real foreign key, and it's the right one for integrity: delete the user and the database knows what to do with their posts. But auth isn't exposed through the Data API, so PostgREST has no users table in public to embed, and select('*, users(email)') fails with PGRST200. Nothing is broken. That table was never meant to be reachable from the browser.
The fixes people reach for next are where the real damage happens. The most common is a view:
-- "Could not find a relationship between 'posts' and 'users' in the schema cache"
-- quick fix: a users view PostgREST can embed through posts.author_id
create view public.users as
select id, email, raw_user_meta_data
from auth.users;
grant select on public.users to authenticated;
It works, which is the problem. PostgREST's docs say it "will infer the foreign keys of a view using its base tables", and that the base table can sit in a private schema. So the error goes away: posts.author_id references auth.users, the view reads auth.users, and the embed now resolves. But a view runs with its owner's rights unless it's created security_invoker, so it reads auth.users as postgres for whoever calls it. With that grant, every signed-in account can request GET /rest/v1/users?select=email and get the email address of every user in the project. Sign-ups are open by default, so "signed-in" means anyone who made an account. Granted to anon, it's everyone with your publishable key.
- Criticalsupabase/migrations/20261122090000_posts_users_view.sql:14
View exposes auth.users through the Data API
Drop the view and keep the fields other users may see in a public.profiles table with RLS (filled by a signup trigger). For the current user's own email, use supabase.auth.getUser(); for admin screens, call auth.admin.listUsers() from server code with the service role.
Supabase's Security Advisor reports this as lint 0002, Exposed Auth Users. The other two shortcuts are just as bad: adding auth to the exposed schemas puts the whole auth schema on the public API, and querying with the service-role key from the browser bypasses RLS everywhere (what to do if that key leaked).
How do I fix "Could not find a relationship between 'posts' and 'users'"?
Keep the fields other users may see in a public.profiles table with RLS, and point your foreign keys at it. Embedding then works through a table you control:
create table public.profiles (
id uuid primary key references auth.users (id) on delete cascade,
display_name text,
avatar_url text
);
alter table public.profiles enable row level security;
create policy "signed-in users read profiles" on public.profiles
for select to authenticated using (true);
-- point posts at profiles (profiles.id is the same uuid as auth.users.id)
alter table public.posts drop constraint posts_author_id_fkey;
alter table public.posts
add constraint posts_author_id_fkey
foreign key (author_id) references public.profiles (id) on delete cascade;
notify pgrst, 'reload schema';
const { data } = await supabase
.from("posts")
.select("id, title, author:profiles(display_name, avatar_url)");
The profile row has to exist before a post can reference it, so create it in a signup trigger. For users who signed up before the table existed, backfill first, or the new constraint won't validate: insert into public.profiles (id) select id from auth.users on conflict do nothing; The full pattern is in how to query the auth.users table without leaking emails. Leave email out of profiles: for the current user's own address, supabase.auth.getUser() already returns it, and an admin screen that lists accounts should call auth.admin.listUsers() from server code.
The sibling errors
The same file produces the other "in the schema cache" messages, and the same triage applies:
Could not find the table 'public.X' in the schema cache(PGRST205, 404): the table itself isn't found. Walkthrough, including the samepublic.userstrap: Could not find the table in the schema cache.Could not find the function public.X(...) in the schema cache(PGRST202, 404): an RPC whose name or argument names don't match. Walkthrough: Could not find the function in the schema cache.Could not find the 'X' column of 'Y' in the schema cache(PGRST204, 400): usually a typo in an insert or update payload, or a column added after the last reload.
Quick self-check
Run this in the SQL Editor to see the foreign keys PostgREST can follow from a table:
select conname as constraint_name,
conrelid::regclass as from_table,
confrelid::regclass as to_table
from pg_constraint
where contype = 'f'
and conrelid = 'public.posts'::regclass;
A to_table of auth.users is cause 3. No rows is cause 1. Two rows to the same table is cause 4.
And check you don't already have a view over auth.users in public:
select v.view_name
from information_schema.view_table_usage v
where v.view_schema = 'public'
and v.table_schema = 'auth' and v.table_name = 'users';
Then grep your migrations for the same thing:
grep -rniE "create (or replace )?view" supabase/migrations/ | grep -i users
grep -rniE "from +auth\.users|join +auth\.users" supabase/migrations/
Does GuardLayer catch this?
Yes. The code scan flags a view in public that reads auth.users without security_invoker, as critical when it's granted to anon or authenticated, and as a warning when it isn't granted yet, since projects created before October 30, 2026 grant new views to both roles automatically. It reads your migrations together, so a later migration that drops the view, revokes it from both roles or makes it security_invoker clears the finding. Live check connects to the running project read-only and checks which tables and views anyone with your publishable key can read.
FAQ
What is PGRST200 in Supabase?
PostgREST's "relationship not found" error, returned with HTTP 400 when you embed a table in a select and no foreign key connects it to the table you're querying.
Why can't I embed auth.users?
Because the auth schema isn't exposed through the Data API. Point your foreign keys at a public.profiles table and embed that instead.
Is a view over auth.users safe if I only select id and email?
No. A view runs with its owner's rights unless it's security_invoker, so anyone who can select from it gets every user's row. Email is exactly the column you don't want to publish.
How do I reload the schema cache?
Run notify pgrst, 'reload schema'; in the SQL Editor. There's no separate clear-cache action.
What's the difference between PGRST200 and PGRST201?
PGRST200 means no relationship was found. PGRST201 means more than one was, and you need to name the one you want with !constraint_name or !column_name in the select.
Check your Supabase Auth settings and tables, free
Connect your Supabase project read-only. GuardLayer checks your Auth settings (leaked passwords, email confirmation, secure email change, token rotation, CAPTCHA, MFA) and your RLS, policies and grants, and says how to fix each problem. It never reads your rows and can't change anything.
Check my Supabase projectPrefer to check code instead? Scan your repo, no signup.