name: supabase-silent-insert-uuid-debug
description: Debug silent INSERT failures in Supabase — UUID default collision causing silent failures
triggers:
- insert not working no error
- cargo não salva
- duplicate key on id column
- uuid default fixed value
Supabase Silent INSERT Failure — UUID Default Collision
Problem
INSERT appears to silently fail in Supabase admin panel. No error shown to user, data doesn't save. Code looks correct, RLS policies look fine.
Root Cause
A column (usually id) has a fixed default UUID instead of uuid_generate_v4(). Every INSERT tries to use the same UUID, violating a UNIQUE or PRIMARY KEY constraint. The error is swallowed by the frontend's error handling.
Symptoms
- - INSERT via Supabase JS returns
{ data: null, error: null }or silently fails - - Direct SQL INSERT gives:
duplicate key value violates unique constraint - -
SELECTworks fine,UPDATEmight work - - The table has 1-2 rows with IDs like
00000000-0000-0000-0000-000000000001 - - RLS policies are
PERMISSIVEwithpublicrole → should allow all - -
SELECTworks butINSERTfails silently - - Error doesn't surface in browser console
Debug Steps
1. Check current UUID defaults
`sql
SELECT column_default FROM information_schema.columns
WHERE table_name = 'your_table' AND column_name = 'id';
`
2. Check existing rows' IDs
`sql
SELECT id FROM your_table ORDER BY created_at;
`
If IDs look like 00000000-... instead of random UUIDs → bad default.
3. Test INSERT directly on DB
`sql
INSERT INTO your_table (name, description) VALUES ('Test', 'desc') RETURNING id;
`
4. Check for constraint violations
`sql
SELECT conname, pg_get_constraintdef(oid)
FROM pg_constraint WHERE conrelid = 'your_table'::regclass;
`
Fix
`sql
-- Remove fixed default
ALTER TABLE your_table ALTER COLUMN id DROP DEFAULT;
-- Add proper UUID generation
ALTER TABLE your_table ALTER COLUMN id SET DEFAULT uuid_generate_v4();
`
Verify fix works:
`sql
INSERT INTO your_table (name) VALUES ('TestFix') RETURNING id;
-- Should return a random UUID like: 97cc404c-a9a3-4107-944b-e919a5564ecf
`
Prevention
When creating tables in Supabase, always use gen_random_uuid() or uuid_generate_v4() as the id column default — not hardcoded UUIDs.