Fix guides · Supabase, Lovable, Bolt, Cursor, v0 ·

Fix Supabase 42501 permission denied for new tables

42501: permission denied for table "tablename"

Supabase returns 42501 permission denied when querying a newly created table in the public schema. Since October 30, 2025, new tables no longer receive automatic SELECT/INSERT/UPDATE/DELETE grants for anon, authenticated, and service_role roles. The table needs explicit GRANT statements for anon/authenticated/service_role, plus RLS policies to control which rows each role can read.

Free · 3 a day · no signup

Common causes – and how to tell which one you have

1. Supabase stopped auto-granting new tables

How to tell: Message is '42501: permission denied for table [table_name]'. The error appears after creating a new table. Since October 30, 2025 new tables no longer receive automatic grants for anon, authenticated, and service_role roles. This applies to new tables in any project, including existing projects; tables created before that date keep their grants.

Fix: Add GRANT statements for the roles your app uses (anon for public read, authenticated for signed-in users, service_role for server-side code). Never grant INSERT/UPDATE/DELETE to anon unless intended.

2. RLS enabled with no policies silently returns zero rows

How to tell: After running GRANT statements, authenticated users see empty results. RLS is enabled on the table but no policy lets the role read rows, so the result set is empty rather than an error.

Fix: Add a complete CREATE POLICY statement such as: CREATE POLICY users_read_own ON [table_name] FOR SELECT TO authenticated USING (auth.uid() = user_id); Verify that rows appear after adding the policy. If the app writes to the table, add matching INSERT/UPDATE/DELETE policies, e.g.: CREATE POLICY users_insert_own ON [table_name] FOR INSERT TO authenticated WITH CHECK (auth.uid() = user_id); CREATE POLICY users_update_own ON [table_name] FOR UPDATE TO authenticated USING (auth.uid() = user_id) WITH CHECK (auth.uid() = user_id); CREATE POLICY users_delete_own ON [table_name] FOR DELETE TO authenticated USING (auth.uid() = user_id);

How to fix it

  1. Open Supabase Dashboard -> SQL Editor for your project.
  2. Enable ROW LEVEL SECURITY: run ALTER TABLE [table_name] ENABLE ROW LEVEL SECURITY;
  3. Run GRANT SELECT ON [table_name] TO anon; and grant INSERT/UPDATE/DELETE only if this table is meant to be publicly writable.
  4. Run GRANT SELECT, INSERT, UPDATE, DELETE ON [table_name] TO authenticated; for tables your signed-in users read and write.
  5. Run GRANT ALL ON [table_name] TO service_role; for server-side code that needs full access. Never put the service_role key in browser code.
  6. Add a complete CREATE POLICY statement such as: CREATE POLICY users_read_own ON [table_name] FOR SELECT TO authenticated USING (auth.uid() = user_id); Adjust the column name (user_id or id) to match your table. Add similar policies for anon as needed. For write access, add matching INSERT/UPDATE/DELETE policies, e.g.: CREATE POLICY users_insert_own ON [table_name] FOR INSERT TO authenticated WITH CHECK (auth.uid() = user_id); CREATE POLICY users_update_own ON [table_name] FOR UPDATE TO authenticated USING (auth.uid() = user_id) WITH CHECK (auth.uid() = user_id); CREATE POLICY users_delete_own ON [table_name] FOR DELETE TO authenticated USING (auth.uid() = user_id);
  7. Test as a signed-in user and as a logged-out visitor to confirm the table returns the right rows for each role.

Using Lovable, Bolt or v0?

In Lovable or Bolt: tell the AI 'Supabase returns 42501 permission denied for a new table. Add GRANT SELECT on [table_name] to anon only if public read is intended, GRANT SELECT/INSERT/UPDATE/DELETE to authenticated, enable RLS with ALTER TABLE ... ENABLE ROW LEVEL SECURITY, add a complete CREATE POLICY (e.g. users_read_own using auth.uid()), and never grant write access to anon unless intended.' Then check Supabase Dashboard -> Authentication -> Policies to confirm the policies appear.

Using Cursor, Claude Code or Windsurf?

Ask Cursor or Claude Code to open Supabase Dashboard -> SQL Editor, run GRANT statements for anon/authenticated/service_role as appropriate, enable ROW LEVEL SECURITY with ALTER TABLE ... ENABLE ROW LEVEL SECURITY, add a complete CREATE POLICY (e.g. users_read_own using auth.uid()), then verify as both a signed-in user and a logged-out visitor. Have them run the query from the app and confirm 42501 is gone.

The “fix” to avoid

Granting INSERT/UPDATE/DELETE to anon, or using check (true) / disabling RLS so anyone can read every row. With RLS off and grants to anon, anyone with your public anon key can read, modify, or delete every row in the table. Keep RLS on, grant only what each role needs, and add row-level policies.

Copy-paste fix prompt for your AI coding tool

Paste this into Cursor, Claude Code, Lovable or Bolt:

Supabase returns '42501: permission denied for table [table_name]' when the app queries a new table. First, enable ROW LEVEL SECURITY: run ALTER TABLE [table_name] ENABLE ROW LEVEL SECURITY; in Supabase Dashboard -> SQL Editor. Then run these GRANT statements in order: GRANT SELECT ON [table_name] TO anon; (only if public read is intended), GRANT SELECT, INSERT, UPDATE, DELETE ON [table_name] TO authenticated; (for signed-in users), GRANT ALL ON [table_name] TO service_role; (server-side only). Then add a complete CREATE POLICY: CREATE POLICY users_read_own ON [table_name] FOR SELECT TO authenticated USING (auth.uid() = user_id); Adjust the column name (user_id or id) to match your table. Add similar policies for anon as needed. Never grant write access to anon unless intended. Never put the service_role key in frontend code. Verify as both a signed-in user and a logged-out visitor.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

Questions people ask

Do I need to grant access to service_role?

Only if your server-side code uses the service_role key to query the table. Client-side code should use the anon key, and service_role should stay out of frontend code.

Should I grant write access to anon?

Only if you truly want anyone on the internet to insert, update, or delete rows. For per-user data, grant write access to authenticated only and add an RLS policy restricting rows to auth.uid().

Does redeploying fix this?

No. GRANT statements take effect in the database immediately. Redeploying won't fix a missing grant — you need to run the GRANT statements in Supabase Dashboard -> SQL Editor.

Official documentation

Related errors

Get fixes like this every week