Home / Error library / Supabase 42501

SupabaseLovable · Bolt · Replit · CursorOct 30, 2026 change

Supabase error 42501: "permission denied for table"

Your AI tool made a new table, and now your app can't read or save anything to it. Here's what's going on and how to fix it without breaking your security.

{
  "code": "42501",
  "message": "permission denied for table your_table",
  "hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.your_table TO anon;"
}

You might also see it as a 401 / 403 in the browser console, or as new row violates row-level security policy.

Short answer

Your app talks to Supabase as one of two roles: anon (logged-out visitors) or authenticated (logged-in users). 42501 means that role isn't allowed to do what it just tried. Either the table has no GRANT for that role, or a Row Level Security (RLS) policy said no. The fix is to add the right grants and the right RLS policies, in the same migration.

What the error means

42501 is Postgres's code for "insufficient privilege." Supabase checks two separate locks on every request from your app:

  1. Table permissions (GRANT). Can this role touch this table at all? If not: permission denied for table ...
  2. Row rules (RLS policies). Which rows can this user see or change? A blocked insert or update also comes back as 42501.

You need both: the grant opens the door, RLS decides which rows get through. Grants with no RLS means anyone with your public anon key can read or wipe the whole table.

Why the AI caused it

For years, Supabase automatically granted anon, authenticated and service_role access to every new table in the public schema. AI coding tools learned from code written under that default, so they often create a table with CREATE TABLE and never write a GRANT.

The Supabase change: Supabase announced that new tables in public will no longer be exposed to the Data API (the REST/GraphQL layer supabase-js uses) automatically. Per their changelog it was opt-in from April 28, 2026, became the default for new projects starting May 30, 2026 (rolled out gradually), and applies to all existing projects on October 30, 2026. After it reaches your project, every new table needs an explicit GRANT. Existing tables keep their current grants. Apps that only use a direct Postgres connection (psql, an ORM, a server with a connection string) aren't affected.
Source: Supabase changelog: Tables not exposed to Data and GraphQL API automatically

So the pattern is: everything worked yesterday, then you asked the AI for a new feature, it added a table, and that one feature throws 42501. The AI will often "fix" it by turning RLS off or using the service role key in the browser. Don't let it do either.

Step-by-step fix

  1. Find the table name. It's in the error message (permission denied for table posts). Note whether the user was logged in (authenticated) or not (anon).
  2. Check its current grants. In Supabase, open SQL Editor and run:
    select grantee, privilege_type
    from information_schema.role_table_grants
    where table_schema = 'public' and table_name = 'posts';
    If anon / authenticated aren't listed, that's your problem.
  3. Grant only what each role needs. Example for a table where logged-in users manage their own posts and visitors can read:
    grant select on table public.posts to anon;
    grant select, insert, update, delete on table public.posts to authenticated;
    grant select, insert, update, delete on table public.posts to service_role;
    If visitors shouldn't see the table at all, skip the anon line.
  4. Turn on RLS and add policies. This is what keeps users out of each other's data (assumes a user_id uuid column):
    alter table public.posts enable row level security;
    
    create policy "Anyone can read posts"
      on public.posts for select
      to anon, authenticated
      using (true);
    
    create policy "Users insert their own posts"
      on public.posts for insert
      to authenticated
      with check ((select auth.uid()) = user_id);
    
    create policy "Users update their own posts"
      on public.posts for update
      to authenticated
      using ((select auth.uid()) = user_id)
      with check ((select auth.uid()) = user_id);
    
    create policy "Users delete their own posts"
      on public.posts for delete
      to authenticated
      using ((select auth.uid()) = user_id);
  5. Put it in the migration. If your project uses migrations (Supabase CLI, Lovable, Cursor), add the grants and RLS in the same migration file that creates the table, so a fresh deploy doesn't break again.
  6. Test as a real user. Log out and try the page, then log in as a test user and try again. Still 42501 on insert/update? Your RLS with check doesn't match the data you're sending. Often user_id isn't being set.
Don't "fix" it this way: disabling RLS, granting everything to anon "to make it work", or putting the service_role key in frontend code. All three make the error go away by making your database public.

Copy-paste prompt for your AI tool

Paste this into Lovable, Bolt, Replit Agent or Cursor. Swap in your table name.

I'm getting Supabase error 42501 "permission denied for table TABLE_NAME".
Supabase no longer auto-grants Data API access to new tables in the public
schema, so new tables need explicit GRANT statements.

Please write ONE SQL migration for public.TABLE_NAME that:
1. Grants only the privileges each role actually needs
   (anon, authenticated, service_role) — explain each grant.
2. Enables Row Level Security on the table.
3. Adds RLS policies so logged-in users can only read/write their own rows
   (using (select auth.uid()) = user_id), plus public read ONLY if this
   feature needs it.
4. Make sure user_id is set on insert.

Rules: do NOT disable RLS, do NOT use the service_role key in client code,
do NOT grant everything to anon to make the error go away.
Then check every other table you've created for the same missing
grants/RLS and list them.

FAQ

What does Supabase error 42501 mean?

42501 is the Postgres code for insufficient privilege. In a Supabase app it usually means the role making the request (anon for logged-out users, authenticated for logged-in users) either has no GRANT on the table, or a Row Level Security policy blocked the insert or update.

Why did my new Supabase table suddenly stop working with permission denied?

Supabase is changing its default so new tables in the public schema are no longer automatically exposed to the Data API. Per Supabase's changelog it became the default for new projects starting May 30, 2026 and applies to all existing projects on October 30, 2026. After that, a new table needs an explicit GRANT before supabase-js can read or write it. Existing tables keep their grants.

Is it safe to just grant everything to anon?

No. A GRANT makes the table reachable through the public API. Only grant the operations each role needs, and always enable Row Level Security with policies so users can only see and change their own rows.

Does this affect my existing tables?

According to Supabase, existing tables keep their current grants and stay reachable. The change affects tables created after it is applied to your project. Apps that connect to Postgres directly (psql, an ORM, or a server with a connection string) are not affected.

I added the GRANT and still get 42501. Why?

If the GRANT is in place, the most common remaining cause is RLS: an INSERT or UPDATE that doesn't satisfy any policy returns 42501. Selecting a column that has column-level restrictions (including via select *) can also return 42501.

Fixed it? Check what else the AI left open.

A missing grant is the loud failure. The quiet ones are tables with RLS off, API keys in your frontend, and auth that only looks like it works. The $15 pre-launch safety check finds them and gives you paste-in fix prompts.

Get the $15 safety check →

Target turnaround 24h · Refund if it finds nothing useful

Sources

Last reviewed Oct 16, 2026. Unbreak My Code is independent and not affiliated with Supabase.

Get new fix pages by email. No spam, unsubscribe anytime.