← All errors · Supabase

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. Never "fix" this by using the service_role key in the browser.

Related errors

Get new fixes weekly

No spam. Unsubscribe anytime. Privacy