If your Supabase app suddenly shows “permission denied for table” (error 42501) on a table you just added, while every older table still works, the table is missing a Postgres GRANT. Since 30 October 2026, Supabase no longer gives the API access to new tables in the public schema automatically. The fix is three statements, run together: grant the roles your app uses, turn on row-level security (RLS), and add policies.
The order matters. The quick fix most AI tools reach for, granting everything to everyone, makes the error go away and can leave your users’ data readable by anyone with your public key. This guide shows how to tell which 42501 you have, the safe fix with copy-paste SQL, and how to stop Lovable, Bolt.new or Cursor creating the next broken table.
What does “permission denied for table” mean in Supabase?
Short answer: Error 42501 means the Postgres role making the request (anon for signed-out visitors, authenticated for signed-in users, service_role for server code) isn’t allowed to touch that table. On a new table, the usual cause is a missing GRANT. Grants decide whether a role can reach a table at all. RLS policies decide which rows it can see. You need both.
The error from the Supabase client looks like this:
{
"code": "42501",
"message": "permission denied for table invoices",
"hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.invoices TO anon;"
}
In the app itself you rarely see that. You see a list that never loads, a “Something went wrong” toast, a form that saves nothing, or a sign-up flow that breaks right after the account is created. Open the browser’s dev tools, go to the Network tab, and look for a red request to /rest/v1/<your_table>. The response body tells you which table and which role.
Why it started happening after 30 October 2026
Until this year, every new Supabase project granted select, insert, update and delete on every table in public to the anon, authenticated and service_role roles. Create a table and it was instantly reachable from the browser, protected only by RLS, if someone remembered to turn it on.
Supabase changed that default in stages, as set out in its breaking change announcement:
| Date | What changed |
|---|---|
| 28 April 2026 | New projects could opt out of automatic exposure |
| 30 May 2026 | Opt-out became the default for new projects (rolled out over a few weeks) |
| 30 October 2026 | Applied to all existing projects |
Two details explain why so many founders are hitting this right now:
- Existing tables are not affected. They keep their old grants, so the screens you use every day keep working. Only tables created after the change fail. That’s why the error shows up the moment you ship a new feature.
- AI tools create tables without a human reading the SQL. Supabase says this is the reason for the change: agents and AI platforms were creating tables, and nobody was checking whether they were protected. That problem was real. In September, UpGuard researchers found more than 16,000 Supabase databases with readable tables, and tied much of it to AI-generated apps with missing or broken RLS.
So the new error is Supabase protecting you. The goal is to fix it without undoing that protection.
Which 42501 do you have?
Not every 42501 is a missing grant. Postgres uses the same code for several permission failures, and each needs a different fix. Match your message to this table before you change anything:
| Error message | What it means | Fix |
|---|---|---|
permission denied for table X on a new table |
Missing grant | Grant + RLS + policies (below) |
new row violates row-level security policy for table X |
Grant is fine, an RLS policy blocked the insert or update | Fix the policy, not the grant |
permission denied for sequence X_id_seq |
Table is granted but its auto-number counter isn’t | Grant usage on the sequence |
permission denied for function X |
A database function (RPC) has no execute grant for that role |
Grant execute to the right role |
permission denied for schema auth (or vault) |
Your code reads a schema the API can never read | Use a view or a function, don’t grant it |
PGRST205: Could not find the table ... in the schema cache |
Not a permissions error: the API hasn’t picked up the new table yet | Reload the schema cache |
You can also see every 42501 from the last few hours in one place. In the Supabase dashboard, open the SQL Editor and run the log query from Supabase’s 42501 troubleshooting guide. It lists the role, the query and the hint for each failure.
How to fix 42501 on a new table (safely)
Do these steps in order. Replace invoices with your table and user_id with the column that stores the owner.
Step 1: Check RLS before you grant anything
This is the step the quick fixes skip. Run this in the SQL Editor:
select relname as table_name, relrowsecurity as rls_on
from pg_class
where relnamespace = 'public'::regnamespace
and relkind in ('r', 'p')
order by rls_on, table_name;
Any table with rls_on = false is a table where a grant opens every row to that role. Turn RLS on and write policies for it before you grant it to anon or authenticated.
Step 2: Grant only what each role needs
Most app tables are private to signed-in users, so signed-out visitors get nothing:
-- Signed-in users: full access, RLS still decides which rows
grant select, insert, update, delete on public.invoices to authenticated;
-- Server code (edge functions, webhooks) using the service role key
grant select, insert, update, delete on public.invoices to service_role;
-- Only if signed-out visitors really need to read it (e.g. public listings):
-- grant select on public.invoices to anon;
Don’t copy the hint blindly. The hint names the role that made the failing request. If it says TO anon for a private table, the real question is why a signed-out request is hitting it. Often the user’s session hadn’t loaded yet when the query ran.
Step 3: Turn on RLS and add policies
alter table public.invoices enable row level security;
create policy "Users read own invoices" on public.invoices
for select to authenticated
using ((select auth.uid()) = user_id);
create policy "Users create own invoices" on public.invoices
for insert to authenticated
with check ((select auth.uid()) = user_id);
create policy "Users update own invoices" on public.invoices
for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
Only add a delete policy if users should be able to delete. With RLS on and no policy for an action, that action is denied, which is what you want.
Step 4: Grant sequences and functions if you use them
If the table has an auto-numbered id (bigint generated ... as identity or serial), inserts also need the sequence:
grant usage, select on sequence public.invoices_id_seq to authenticated, service_role;
If your app calls a database function with supabase.rpc('my_function'), grant execute to the roles that call it, and nobody else:
grant execute on function public.my_function() to authenticated;
Step 5: Test it as a stranger
A working app isn’t proof the data is safe. Ask for the table using only your public (anon or publishable) key, with no user signed in:
curl "https://YOUR-PROJECT.supabase.co/rest/v1/invoices?select=*&limit=5" \
-H "apikey: YOUR_PUBLISHABLE_KEY"
- A 42501 error, or
[]on a table that has rows: signed-out visitors can’t read it. Good. - Rows come back: anyone on the internet can read them. Go back to step 1.
Then sign in as two different test users and check that each one sees only their own rows.
The quick fix that leaks your data
When the error first appears, a search or an AI assistant will often suggest this:
-- Don't run this as a fix
grant select, insert, update, delete on all tables in schema public
to anon, authenticated, service_role;
It works, in the sense that the error disappears. But it grants every table in public, including any that were created with RLS off. Those tables become readable, and often writable, with the public key that ships in your app’s front end. That’s exactly how the databases in the UpGuard research were exposed.
Supabase’s own docs say to use grants and RLS together on every exposed table. Grant table by table, after checking RLS, and keep internal tables (logs, webhook events, admin data) ungranted or in a separate schema.
Other places the change breaks things
Grant problems don’t only show up on the screen you just built. These are the ones I check next.
Webhooks and edge functions
A Stripe webhook or any edge function that writes with the service role key also needs a grant on new tables. The service role key bypasses RLS, but it doesn’t bypass grants. If payments go through and the new subscriptions table stays empty, check the function’s logs for 42501.
There’s a second trap here. Supabase’s RLS docs note that a secret key only bypasses RLS when the request carries no user token. If your function creates its client with the secret key and also passes along the user’s Authorization header, it runs as that user, under their policies.
Views
Views run as the user who created them, which is usually postgres, so by default they skip the RLS on the tables underneath. If you grant a view to anon or authenticated, create it with security_invoker so it respects RLS (Postgres 15 and later):
create view public.invoice_totals
with (security_invoker = true) as
select user_id, sum(amount) as total
from public.invoices
group by user_id;
Fresh environments and preview branches
If your migrations were written before the change, they never contained grants, because Supabase added them automatically. Rebuild the database from those migrations (supabase db reset, a new staging project, a preview branch) and every table can come up unreachable. Add a migration that grants the tables explicitly, so a fresh environment matches production.
“Could not find the table in the schema cache”
That’s PGRST205, not 42501. The API caches your schema and hasn’t seen the new table yet. Run this in the SQL Editor:
notify pgrst, 'reload schema';
Stop your AI builder creating the next broken table
Lovable, Bolt.new, Replit, Cursor and Claude Code all create tables for you. Many of them learned Supabase before grants were needed, so they write a create table, maybe an RLS policy, and no grant. Some will “fix” the resulting error with the blanket grant above.
Add a rule to your project’s instructions (Lovable’s project knowledge, a .cursorrules file, CLAUDE.md or similar):
Every new table in Supabase must be created in one migration with:
1. explicit GRANTs to only the roles that need it (authenticated, service_role; anon only for truly public data),
2. ALTER TABLE ... ENABLE ROW LEVEL SECURITY,
3. policies for each allowed action, scoped to auth.uid().
Grant sequences used by identity or serial columns.
Never grant on ALL TABLES IN SCHEMA public. Never disable RLS to fix an error.
Never use the service role key in client code.
Supabase also publishes an agent skill for AI coding tools that includes the grant step. And whatever tool you use, open the migration before you approve it, and look for the three parts.
Supabase’s Security Advisor (in the dashboard under Advisors) also flags tables with risky access. Check it after every feature that adds a table.
42501 fix checklist
- Read the full error: table, role and message
- Confirmed it’s a missing grant, not an RLS policy or schema cache issue
- RLS is on for the table before granting anything
- Granted only the roles and actions the feature needs
- Policies scoped to
auth.uid()for each allowed action - Sequences and functions granted where used
- Webhooks and edge functions tested against the new table
- Views use
security_invoker = true - Tested with only the public key: no private rows come back
- Grants added to migrations, and an instruction added to your AI builder
When to bring in a developer
If one new table broke and the steps above fixed it, you’re done. It’s worth getting help when you find tables with RLS off that hold real user data, when someone already ran the blanket grant on a live app, when payments or sign-ups depend on the broken tables, or when your migrations no longer rebuild a working database. Those are security and data problems, not just an error message, and guessing at SQL in production makes them worse.
If your Lovable or Bolt.new app started failing with “permission denied for table”, I can find every table and function affected, add the right grants and policies, check nothing is exposed, and fix the migrations so the next feature doesn’t break. See how I fix Lovable apps and Bolt.new apps, or send me the error you’re seeing. For a wider review of an AI-built app, read common Lovable app issues and how to fix them.
FAQ
Why do my old Supabase tables work but my new one returns 42501?
Tables that existed before your project got the 30 October change kept their grants. New tables in public now start with no grants at all, so the API can’t reach them until you grant access. That’s why only the newest feature breaks.
Is it safe to grant select to anon in Supabase?
Only if RLS is on and the policies allow exactly the rows a signed-out visitor should see, such as published products or public profiles. With RLS off, a grant to anon makes the whole table readable by anyone who has your public key, and that key is in your front-end code.
What’s the difference between a grant and an RLS policy?
A grant decides whether a role can use a table at all, and for which actions. An RLS policy decides which rows that role can read or change. Supabase checks the grant first, then RLS. A table exposed to the browser needs both.
Does the change affect Lovable Cloud apps?
Lovable Cloud runs on Supabase, so if you see “permission denied for table” on a new table there, the cause and fix are the same. Apply the grants through a migration in the project rather than by editing tables by hand, so they stay in the code.
Can I turn the old behaviour back on?
Supabase’s announcement includes rollback SQL that restores automatic grants on new tables (written for projects that opted in early). Even where that still works, it brings back the risk the change was made to remove: every new table reachable from the browser the moment it’s created. Explicit grants in your migrations are the long-term fix.
Further reading
- Breaking change: tables not exposed to the Data API automatically (Supabase)
- Database API 42501 errors (Supabase)
- Securing your API: grants and RLS (Supabase)
- Row Level Security (Supabase)
- Reload the PostgREST schema (Supabase)