new row violates row-level security policy for table

Saving data fails with "new row violates row-level security policy"? Add an INSERT policy with a WITH CHECK rule and send the right user_id.

Last edited October 18, 2026

On this page

What it means in plain English

Supabase refused to save a new or updated row because your security rules (RLS) don't allow that user to create it.

If you built the app in Lovable on its built-in backend: since 12 November 2026, when you publish a project that has unresolved critical security findings, Lovable asks you to review them first. You can open them in the Security view, publish anyway, or ask Lovable to fix them all in one request, which uses one of your free fixes. This prompt is not a lock, and it does not replace Row Level Security policies. Source: Lovable changelog, 12 Nov 2026, https://docs.lovable.dev/changelog (opens in a new tab)

Supabase Launch Safety Pack

RLS checklist, policy templates, key migration and environment variable setup.

See what’s inside

Secure checkout by Stripe

One-time payment through Stripe. Priced in USD. Local taxes such as UK VAT may be added at checkout.

Likely causes

  • No INSERT (or UPDATE) policy exists on the table.
  • The policy's with check requires user_id = auth.uid() but your app doesn't send user_id, or sends a different value.
  • The user isn't signed in, so auth.uid() is null.
  • An UPDATE has no matching SELECT policy; Supabase notes UPDATE needs a SELECT policy to work.

How to fix it, step by step

  1. Supabase → Database → Policies, find the table.
  2. Add an INSERT policy, e.g.:
create policy "Users can create their own rows"
on public.todos for insert
to authenticated
with check ( (select auth.uid()) = user_id );
  1. For edits, add both an UPDATE policy (using + with check) and a SELECT policy.
  2. Make the app set user_id to the signed-in user's id when inserting (or give the column a default of auth.uid()).
  3. Confirm the user is signed in before saving.
  4. If uploading files, see the separate Supabase Storage page: Storage uses its own storage.objects policies.

How to check it worked

  • Submit the form again; the row should save and appear in Table Editor.
  • Try saving while signed out; it should still be refused.

If the insert succeeds and only .insert().select() returns 42501, the missing piece is a SELECT grant or a SELECT policy for the returned row. See Supabase insert works, .select() returns 42501.

A policy that reads the same table can fail with infinite recursion instead of this message. See infinite recursion detected in policy.

Sources

Tool to consider: Supabase.

Supabase Launch Safety Pack

RLS checklist, policy templates, key migration and environment variable setup.

See what’s inside

Secure checkout by Stripe

One-time payment through Stripe. Priced in USD. Local taxes such as UK VAT may be added at checkout.