What it means
Another table has a foreign key that points at auth.users, and at least one row in it
still references the user you are deleting. A foreign key created with a plain
references auth.users uses the default rule, NO ACTION, which means “refuse the
delete while children exist”. Supabase Auth runs the delete, Postgres refuses it with SQLSTATE
23503, and the dashboard or auth.admin.deleteUser() shows the generic
Database error deleting user. The detailed line is in the Postgres logs.
Step 1: list every foreign key that points at auth.users
select conrelid::regclass as child_table,
conname as constraint_name,
pg_get_constraintdef(oid) as definition
from pg_constraint
where contype = 'f'
and confrelid = 'auth.users'::regclass;A definition without ON DELETE is the one that blocks the delete. Repeat the query with 'public.profiles'::regclass as well: if posts references profiles without a rule, deleting the user cascades into profiles and then fails one level further down.
Step 2: decide what should happen to the child rows
- Data that belongs only to the user (profile, settings, drafts):
ON DELETE CASCADE. Supabase's own user-management guide definesprofiles.idthis way. - Records you must keep (orders, invoices, audit entries):
ON DELETE SET NULL, with a nullable column. The record survives without the person. - Things that must block deletion until someone acts: keep
NO ACTIONorRESTRICT, and delete or reassign those rows first in your own code.
Step 3: change the constraint
Drop and re-add it in one statement, keeping the same name:
alter table public.profiles
drop constraint profiles_id_fkey,
add constraint profiles_id_fkey
foreign key (id) references auth.users (id) on delete cascade;
-- keep the order, forget the person
alter table public.orders
drop constraint orders_user_id_fkey,
add constraint orders_user_id_fkey
foreign key (user_id) references auth.users (id) on delete set null;On a large child table, adding a foreign key scans it under a lock. Add it with NOT VALID and run alter table … validate constraint … afterwards to keep the lock short. Index the foreign key column too: every delete in auth.users has to find the matching child rows, and without an index that is a full scan.
Other things that block a user delete
- Storage files. Supabase's docs say you cannot delete a user who still owns objects in
Storage. Remove the user's files with the Storage API (
supabase.storage.from(bucket).remove([...])) or reassign them first. Deleting rows fromstorage.objectswith SQL does not delete the files. - Triggers on auth.users. A custom
after deletetrigger that errors produces the same generic message. The Postgres log names the function.
How to verify
Test on a throwaway user inside a transaction in the SQL Editor:
begin;
delete from auth.users where id = '00000000-0000-0000-0000-000000000000'; -- a test user's id
select count(*) from public.profiles where id = '00000000-0000-0000-0000-000000000000'; -- expect 0
rollback;No error, and the child rows are gone (or set to null) inside the transaction. Then delete the test user from the dashboard: the toast should say the user was deleted.
FAQ
Is ON DELETE CASCADE safe for auth.users?
For data that only makes sense with the user, yes, and it is what Supabase's docs use for profiles. For business records you must keep, use ON DELETE SET NULL instead so a user delete never removes orders or invoices.
Related guides
- Supabase “Database error saving new user” – find the failing trigger and fix it
- “relation does not exist” in Postgres and Supabase – schema, quotes, search_path, cache
- Postgres “new row for relation … violates check constraint” – find the rule and fix it
- Supabase “JWT expired” – why the token went stale and how to keep it fresh
More in Auth, JWT and secrets · all guides