Fix guides · Lovable, Bolt, Cursor, v0, Claude Code, Replit ·

Fix Supabase "permission denied for table" (42501) - missing GRANT

permission denied for table "profiles" (code 42501)

Supabase's default privileges may not grant read/write on new tables, so tables need explicit GRANT statements. The error appears when the API role lacks the needed privilege on the table.

Free · 3 a day · no signup

Common causes – and how to tell which one you have

1. Missing grant on the table

How to tell: The API role has no GRANT on the table. RLS policies only filter rows for roles that already have the necessary GRANT.

Fix: Grant select, insert, update, delete on table public.profiles to the appropriate role. Add the grant in the same migration file that creates the table so new environments inherit the privileges.

How to fix it

  1. In the Supabase dashboard, open the SQL Editor and run: select grantee, privilege_type from information_schema.role_table_grants where table_name = 'profiles'; to see which roles have which privileges.
  2. The Postgres 42501 message does not name the failing role. Check the Authorization header (or no user session exists) to see if anon or service_role was used. You can find the role from the client's auth state or request headers.
  3. Grant the needed privileges: grant select, insert, update, delete on table public.profiles to authenticated; and grant select on table public.profiles to anon; only if anonymous reads are actually intended.
  4. Confirm row-level security still applies: select relname, relrowsecurity from pg_class where relname = 'profiles'; should show true. If RLS is off, enable it and add policies for each operation you allow.
  5. Re-run the failing request in your app. The 42501 permission denied error should be replaced by normal data, or by a row-level security policy error, which means you now have the grant but need to fix the policy.
  6. If the table is created by a migration, put the grant in the same migration file so new environments don't repeat the problem.

Using Lovable, Bolt or v0?

In Lovable or Bolt, tell the AI: "Inserts fail with 'permission denied for table profiles' (42501). This is a missing GRANT, not an RLS policy. Add the grants for the authenticated role on the profiles table to the migration, keep RLS enabled with a policy for each operation, and show me the request succeeding." Then check the migration file and the SQL editor output, because the builder often re-adds policies that don't fix a grant problem.

Using Cursor, Claude Code or Windsurf?

Ask Cursor or Claude Code to first print the output of select grantee, privilege_type from information_schema.role_table_grants where table_name = '<table>'; and select relrowsecurity from pg_class where relname = '<table>'; before changing anything. If grants are missing, have it add them to the migration. Confirm the app request succeeds and RLS is still enabled with a policy per operation.

The “fix” to avoid

Agents see 'permission denied' and keep adding row-level security policies, which never fixes a missing GRANT. Others disable RLS or switch to the service_role key in the browser, which exposes every row to anyone. Never ship the service_role key to the client; keep the anon/auth roles and add the correct grants plus policies.

Copy-paste fix prompt for your AI coding tool

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

My Supabase app fails with: permission denied for table "profiles" (code 42501). This is a GRANT problem, not a row-level security policy problem, so do not just add another RLS policy. First run in the SQL editor: select grantee, privilege_type from information_schema.role_table_grants where table_name = 'profiles'; and tell me which roles lack which privileges. Then add the minimal grants the app needs (for example grant select, insert, update, delete on table public.profiles to authenticated;), keep RLS enabled, and make sure a policy exists for each operation. If the table is created by a migration, add the grant to that migration. Show me the app request succeeding after the change.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

Questions people ask

What's the difference between 42501 permission denied and new row violates row-level security policy?

Both use code 42501, but they're different layers. permission denied for table means the role has no GRANT on the table. new row violates row-level security policy means the role has the grant but an RLS policy blocked the row. Grants first, then policies.

Why did this start happening on a new project?

Supabase's default privileges no longer automatically grant read/write on new tables in newer projects. Tables need explicit GRANT statements for the API roles (anon, authenticated, service_role). Add the grant in the same migration file that creates the table.

Can I just use the service_role key to make it work?

service_role bypasses RLS and has broad privileges, so it 'fixes' the error, but only in a server or Edge Function. Putting it in browser code lets any visitor read and write all data. Use it only server-side.

Related errors

Get fixes like this every week