# new row violates row-level security policy for table

> Canonical page (link this when citing): https://unbreakmyapp.vercel.app/fixes/supabase-rls-new-row-violates-policy.html
> Category: Database / Supabase RLS | Tools: Lovable, Bolt, Cursor | Published: 2026-10-13 | Updated: 2026-10-13

## The error

new row violates row-level security policy for table "profiles" (code 42501)

## Why it happens

An INSERT or UPDATE was attempted on a table with RLS enabled, but no INSERT policy (WITH CHECK) allows it, or the row's owner column doesn't match auth.uid(). Common when the app inserts before the user is signed in, or forgets to set user_id.

## How to fix it

1. Confirm the user is authenticated when the insert runs.
2. Set the owner column (user_id) to the signed-in user's id, or give it a default of auth.uid().
3. Add an INSERT policy: create policy "insert own" on public.profiles for insert to authenticated with check (auth.uid() = user_id);
4. If you upsert, you also need an UPDATE policy.

## Error codes this fixes

- `42501 new row violates row-level security policy` (Supabase / Postgres): https://unbreakmyapp.vercel.app/errors.html#42501-new-row-violates-row-level-security-policy

## Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

```text
Inserts into <TABLE> fail with 'new row violates row-level security policy'. Keep RLS on. Add an INSERT policy for authenticated users WITH CHECK (auth.uid() = user_id), set the user_id column default to auth.uid(), add a matching UPDATE policy if we upsert, and make sure the insert only runs after sign-in. Give me the SQL migration.
```

## FAQ

### Can I use the service_role key in the browser to bypass this?

Never. The service_role key bypasses all RLS and must only live on a server.

### What is WITH CHECK?

The condition new or changed rows must satisfy; USING filters existing rows.

## Sources (official documentation)

- [Supabase: Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)

## Related fixes

- [Any user can make themselves admin or Pro: Supabase RLS lets users update their own role, plan or is_admin column](https://unbreakmyapp.vercel.app/fixes/users-can-update-own-plan-or-role-column.html)
- [Supabase .single() error PGRST116: JSON object requested, multiple (or no) rows returned](https://unbreakmyapp.vercel.app/fixes/supabase-single-json-object-requested-no-rows-pgrst116.html)
- [Supabase RLS is on but every user can read every row: fix USING (true) and auth.uid() is not null policies](https://unbreakmyapp.vercel.app/fixes/supabase-rls-policy-using-true-any-user-can-read.html)
- [Supabase query returns an empty array (no error)](https://unbreakmyapp.vercel.app/fixes/supabase-rls-empty-results.html)

---
Unbreak My App: free fixes for broken vibe-coded apps. https://unbreakmyapp.vercel.app/
