The Prompt BakeryTemplates and prompts

Fix · Supabase and databases

Insert fails: new row violates row-level security policy

Blocks your work

What you may see

  • Saving a form or creating a record fails for logged-in or anonymous users
  • My app cannot save the form data into the database table
  • The error mentions row-level security or a policy

Most likely cause

Row level security is on for the table, and no policy lets this kind of user (anonymous or logged in) add that row.

Check first (about two minutes)

  1. In the Supabase dashboard open the table's policies page: is there an INSERT policy? (the page may be labelled differently)
  2. Check which role makes the call: logged out (anon) or logged in (authenticated).

The fix prompt

What you type here never leaves your browser. The search runs on this page, and nothing is sent to a server or to an AI.

Kept only in this browser, on this device. Keys and passwords are removed before anything is saved.

Prompt language

Paste it into Claude, ChatGPT, Gemini or Cursor, then follow what it says.

After you tried it, did it work?

Steps

  1. Show me the table definition and its current policies (use the SQL editor or migration files).
  2. Tell me who SHOULD be allowed to insert (anyone, logged-in users, only the owner of the row) and ask me if unclear.
  3. Write the narrowest INSERT policy with a WITH CHECK clause that matches (for example user_id = auth.uid()), for the right role only.
  4. Give me the policy as a migration file and tell me how to test it as a normal user, not as the admin.

Do not do this

  • Do not write a policy with using (true) for all roles on a table with private data.
  • Do not turn row level security off.
  • Do not use the service role key in the browser to get around it.

Related

Try another entry

How can we help?

What do you need?
Your email, so we can reply (optional)Only enter your own email. We reply there.