← All errors · SupabaseSupabase database & RLS errors
permission denied for table (Data API 42501)
Exact error
{"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;"}What it means
This often hits Lovable, Bolt, and Cursor apps after they create a new public table and query it immediately. PostgREST/Data API (supabase-js, /rest/v1, GraphQL) rejected the request because the current Postgres role (anon, authenticated, or service_role) has no table privilege for that operation. This is a GRANT problem, not an RLS policy miss. RLS runs only after grants succeed. Starting Oct 30, 2026, Supabase applies a breaking change to all existing projects: new tables in the public schema are no longer auto-granted to anon/authenticated/service_role, so new tables fail with this error until you grant explicitly. Existing tables keep their current grants. Direct Postgres connections (psql, ORM connection string) are unaffected.
See also: official Supabase guide: Database API 42501 errors.
Likely causes
- New table created in public after the project opted into (or was rolled onto) "tables not auto-exposed to Data API" — no GRANT yet.
- Oct 30, 2026 rollout to all existing projects: any new public table without explicit grants breaks supabase-js /rest / GraphQL.
- AI/CLI/migration created the table without GRANT statements.
- service_role also needs an explicit grant — Edge Functions and server jobs writing new tables fail the same way.
- Custom schema without grants to the API roles.
- Column-level privileges blocking SELECT * (select expands to forbidden columns).
How to fix it
Check which roles already have grants on the table. An empty result, or a missing privilege for anon, authenticated or service_role, is this error:
select grantee, privilege_type from information_schema.role_table_grants where table_schema = 'public' and table_name = 'your_table' order by grantee, privilege_type;Treat grant, RLS and policies as one unit. Grant only the privileges each role needs, enable RLS, then add policies. Granting without RLS leaves the table open to anyone with the anon key:
-- 1. Grant the privileges the role needs grant select on public.your_table to anon; grant select, insert, update, delete on public.your_table to authenticated; grant select, insert, update, delete on public.your_table to service_role; -- 2. Enable RLS alter table public.your_table enable row level security; -- 3. Add the policies you need create policy "users can read their own rows" on public.your_table for select to authenticated using ( (select auth.uid()) = user_id );The JSON hint names the missing privilege and role, for example GRANT SELECT ON public.your_table TO anon. Run that GRANT, then still enable RLS and add policies for that role.
If an AI tool, CLI or migration created the table, update its prompt (or install the Supabase agent skill) so every CREATE TABLE ships with GRANT, ENABLE ROW LEVEL SECURITY and CREATE POLICY in the same migration.
Optional: opt an existing project into the new default early, so future public tables are not auto-granted. Existing tables keep their current grants:
alter default privileges for role postgres in schema public revoke select, insert, update, delete on tables from anon, authenticated, service_role; alter default privileges for role postgres in schema public revoke usage, select on sequences from anon, authenticated, service_role;Do not disable RLS to make the error go away, and do not put the service_role key in the browser. Grant the role the app actually uses, enable RLS, and write policies for that role.
If Lovable, Bolt, Cursor, or another AI tool created the table, paste this so the next change includes GRANT, RLS, and policies together:
The Data API returns {"code":"42501","message":"permission denied for table your_table"}. This is a missing GRANT, not an RLS miss. Grant only the privileges the role needs, enable RLS, and add policies in the same change. Do not disable RLS and do not put the service_role key in the browser.
Still stuck after trying this? Get it fixed for $49, or you don't pay.
Prevent this next time
- Keep schema and RLS policies in migrations (`supabase migration new`) instead of editing production by hand.
- Test each policy as both an anonymous and a signed-in user before shipping.
FAQ
What does "permission denied for table (Data API 42501)" mean?
This often hits Lovable, Bolt, and Cursor apps after they create a new public table and query it immediately. PostgREST/Data API (supabase-js, /rest/v1, GraphQL) rejected the request because the current Postgres role (anon, authenticated, or service_role) has no table privilege for that operation. This is a GRANT problem, not an RLS policy miss. RLS runs only after grants succeed. Starting Oct 30, 2026, Supabase applies a breaking change to all existing projects: new tables in the public schema are no longer auto-granted to anon/authenticated/service_role, so new tables fail with this error until you grant explicitly. Existing tables keep their current grants. Direct Postgres connections (psql, ORM connection string) are unaffected.
What usually causes it?
New table created in public after the project opted into (or was rolled onto) "tables not auto-exposed to Data API" — no GRANT yet. Oct 30, 2026 rollout to all existing projects: any new public table without explicit grants breaks supabase-js /rest / GraphQL. AI/CLI/migration created the table without GRANT statements. service_role also needs an explicit grant — Edge Functions and server jobs writing new tables fail the same way. Custom schema without grants to the API roles. Column-level privileges blocking SELECT * (select expands to forbidden columns).
How do I fix it?
1. Check which roles already have grants on the table. An empty result, or a missing privilege for anon, authenticated or service_role, is this error: 2. Treat grant, RLS and policies as one unit. Grant only the privileges each role needs, enable RLS, then add policies. Granting without RLS leaves the table open to anyone with the anon key: 3. The JSON hint names the missing privilege and role, for example GRANT SELECT ON public.your_table TO anon. Run that GRANT, then still enable RLS and add policies for that role. 4. If an AI tool, CLI or migration created the table, update its prompt (or install the Supabase agent skill) so every CREATE TABLE ships with GRANT, ENABLE ROW LEVEL SECURITY and CREATE POLICY in the same migration. 5. Optional: opt an existing project into the new default early, so future public tables are not auto-granted. Existing tables keep their current grants: 6. Do not disable RLS to make the error go away, and do not put the service_role key in the browser. Grant the role the app actually uses, enable RLS, and write policies for that role. 7. If Lovable, Bolt, Cursor, or another AI tool created the table, paste this so the next change includes GRANT, RLS, and policies together:
Last checked against official docs on . Sources: Supabase changelog: tables not exposed to Data API automatically, Official Supabase Knowledge Base: Database API 42501 errors.
Related errors
- new row violates row-level security policy for table
- RLS Disabled in Public: Table is public, but RLS has not been enabled
- Supabase select returns an empty array (no error)
- relation "public.x" does not exist
More Supabase errors and fixes →
Tools that help
- Railway: Deploy backends and databases; new users get $20 credit.
Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.
Get new fixes weekly
No spam. Unsubscribe anytime. Privacy