← All errors · SupabaseSupabase database & RLS errors

new row violates row-level security policy for table

Exact error

new row violates row-level security policy for table "todos"

What it means

Row Level Security is enabled on the table and no policy allows the current user to insert (or update) this row. Postgres error code 42501.

Likely causes

How to fix it

  1. Add an insert policy for authenticated users that own the row:

    create policy "Users can insert their own todos"
    on public.todos for insert
    to authenticated
    with check ( (select auth.uid()) = user_id );
  2. Make sure the insert sets user_id (or give the column a default):

    alter table public.todos
      alter column user_id set default auth.uid();
  3. Confirm the client actually has a session (supabase.auth.getUser()) before inserting.

  4. If insert works but `.insert(...).select()` or upsert fails with this error, add a matching SELECT policy for the same role, or drop `.select()` when you do not need the returned row.

    create policy "Users can read their own todos"
    on public.todos for select
    to authenticated
    using ( (select auth.uid()) = user_id );
  5. Never "fix" this by using the service_role key in the browser.

  6. Also check table grants: if the role has no insert grant at all, Postgres rejects the request before any policy runs. "permission denied for table" with a GRANT hint is supabase-permission-denied-for-table; "new row violates row-level security policy" is this page. Grant only what the role needs:

    grant select, insert on table public.todos to authenticated;

Still stuck after trying this? Get it fixed for $49, or you don't pay.

Prevent this next time

FAQ

What does "new row violates row-level security policy for table" mean?

Row Level Security is enabled on the table and no policy allows the current user to insert (or update) this row. Postgres error code 42501.

What usually causes it?

RLS enabled with no INSERT policy. Policy WITH CHECK condition fails, e.g. user_id not set to auth.uid(). Request made with the anon key and no logged-in session. Insert or upsert chains .select() (or returns the new row), so Postgres also checks a SELECT policy on the new row. An INSERT-only policy is not enough.

How do I fix it?

1. Add an insert policy for authenticated users that own the row: 2. Make sure the insert sets user_id (or give the column a default): 3. Confirm the client actually has a session (supabase.auth.getUser()) before inserting. 4. If insert works but `.insert(...).select()` or upsert fails with this error, add a matching SELECT policy for the same role, or drop `.select()` when you do not need the returned row. 5. Never "fix" this by using the service_role key in the browser. 6. Also check table grants: if the role has no insert grant at all, Postgres rejects the request before any policy runs. "permission denied for table" with a GRANT hint is supabase-permission-denied-for-table; "new row violates row-level security policy" is this page. Grant only what the role needs:

Last checked against official docs on . Sources: Supabase docs: Row Level Security.

Related errors

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