Skip to content
>_VibeUnstuck

permission denied for table (42501)

Last verified:

The fix

permission denied for table (42501): the Supabase role has no GRANT. Postgres stops before Row Level Security. Grant that command and leave RLS on.

  1. 1

    Read the message before changing policies

    If the body says permission denied for table or permission denied for schema, stay on this page. If it says new row violates row-level security policy, the role already has a GRANT and a policy blocked the row. If it says Invalid API key, the request never reached the table. The code 42501 appears on both the GRANT failure and the RLS failure, so match the message, not the code alone.

  2. 2

    List grants in the dashboard or in SQL

    In the Supabase SQL editor, list privileges for the table in the error. An empty result for anon and authenticated means the Data API cannot use the table. The Table Editor’s Data API exposure badge shows the same gap. The SQL editor itself runs as a privileged role, so a query that works there does not prove the API role has a GRANT.

    select grantee, privilege_type
    from information_schema.role_table_grants
    where table_schema = 'public'
      and table_name = 'your_table'
      and grantee in ('anon', 'authenticated', 'service_role');
  3. 3

    Add the GRANT in the migration

    Grant only the commands that role needs. A public read can be select for anon. Writes from a signed-in user belong on authenticated. Put the statement in the same migration that creates the table so the next generated table does not ship the same hole. If the error says permission denied for sequence, grant usage, select on that sequence too.

    grant select on table public.your_table to anon;
    grant select, insert, update, delete on table public.your_table to authenticated;
  4. 4

    Leave RLS on, and keep the service role on the server

    Do not fix a missing GRANT by disabling RLS. After the GRANT, the policies still have to allow the row. Do not put the service_role key in the browser, a Vite app, or a NEXT_PUBLIC_ / VITE_ variable. Granting the service_role database role inside SQL is separate from shipping that key to the client.

Why it happens

Supabase used to grant select, insert, update, and delete on new tables in public to anon, authenticated, and service_role. That default is going away. New projects have used the stricter default since May 30, 2026, and existing projects follow on October 30, 2026. Tables created before the change keep their grants. A table created after it is invisible to the Data API until a migration says GRANT. PostgREST then returns code 42501 and permission denied for table ..., often with a hint that names the statement to run.

This is not the Row Level Security error new row violates row-level security policy, and it is not Invalid API key. Those fail for different reasons. Grants decide whether a role may touch the table at all. Policies decide which rows. Vibe-coded starters often enable RLS and add a policy, then skip the GRANT, so the policy never gets a chance to run.

The next error you'll probably hit

Once this is fixed, the usual follow-up is relation "public.profiles" does not exist. relation "public.profiles" does not exist (42P01): that table is missing here. PGRST205 means the schema cache lacks it. Run the migration on this project.

Prompt to paste back into your AI tool

Paste this above the error.

The Supabase Data API returns code 42501 and this message:

permission denied for table "TABLE"

Do not disable RLS. Do not put the service_role key in the browser or in a NEXT_PUBLIC_ / VITE_ variable. Do not rewrite policies unless the message is actually "new row violates row-level security policy". This is not an invalid API key.

1. Show the grants on this table for anon and authenticated.
2. Add a GRANT in the migration for the privileges that role needs. Keep RLS enabled.
3. If the client runs in the browser, it must keep using the anon or publishable key.
4. Paste the SQL only. Do not swallow the error or return an empty list to hide it.

Common questions

+Why does the same query work in the SQL editor?

The SQL editor runs as a role that owns the table. supabase-js uses anon until a session exists, then authenticated. Those roles need their own GRANT.

+Will turning off RLS clear a permission denied error?

No. Postgres checks the GRANT before it checks policies. Disabling RLS only removes the row filter, and it leaves every granted role able to see every row.

Related errors