Fix guide · updated 2026-11-16
Supabase "Database error deleting user"
{"code":500,"error_code":"unexpected_failure","msg":"Database error deleting user"}
You delete a user, in the dashboard under Authentication → Users or with supabase.auth.admin.deleteUser(), and it fails with "Database error deleting user". Or, from recent versions of Supabase Auth, with the database's own message: update or delete on table "users" violates foreign key constraint "profiles_id_fkey" on table "profiles". Something in your database still points at that user, and Postgres won't leave it pointing at nothing. We ran Supabase Auth itself (version 2.198, November 2026) with the usual table setups to see what blocks a delete and what each fix does.
What the error means
Deleting a user removes their row from auth.users. Supabase's own tables, like sessions and identities, follow by themselves. Your tables don't: each foreign key that references auth.users says what happens to the rows that point at the deleted user, and with no rule, which is the default, Postgres refuses the delete. In our test:
profiles.idreferencingauth.userswith no rule: the delete failed with the foreign-key message above (code23503, HTTP 500),- the same key with
on delete cascade: the delete worked, and the profile went with the user, - a trigger on
auth.usersthat hit a permission error: the delete failed with "Database error deleting user".
Supabase Auth passes constraint errors on as they are, so if your message names a table, that's the table to fix. Other database errors, like a failing trigger, come back as the generic "Database error deleting user".
The one-minute check
In the SQL Editor, list your tables that point at users:
select conrelid::regclass as your_table, conname as constraint_name, pg_get_constraintdef(oid) as definition
from pg_constraint
where confrelid = 'auth.users'::regclass and contype = 'f'
and connamespace <> 'auth'::regnamespace;
A definition that ends with ON DELETE CASCADE or ON DELETE SET NULL has a rule. One that ends with just REFERENCES auth.users(id) blocks the delete of any user who has a row in that table.
If the error names a table that isn't in this list, it points at one that is: posts pointing at profiles, for example. In our test, a profiles table with on delete cascade still couldn't go, because posts pointed at it with no rule. Run the same query with 'public.profiles'::regclass in place of 'auth.users'::regclass to see those.
1. Rows that belong only to the user: on delete cascade
For a profile, settings, or anything that means nothing without its user, let the rows go with the user. Supabase's docs recommend on delete cascade for a profiles table. Replace the key, with the constraint name from the check:
alter table public.profiles
drop constraint profiles_id_fkey,
add constraint profiles_id_fkey foreign key (id) references auth.users (id) on delete cascade;
Do the same for every table in the chain: if posts points at profiles, it needs a rule too. Cascade deletes those rows for good, so check the list before you run it.
2. Rows you must keep: on delete set null
Orders, invoices, or messages in a shared thread may have to outlive the user. Keep the row and forget who it belonged to. The column has to accept null: in our test, set null on a not null column failed with null value in column "user_id" of relation "invoices" violates not-null constraint (23502).
alter table public.orders alter column user_id drop not null;
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;
In our test, the order stayed, with an empty user_id.
3. A trigger that runs when a user is deleted
Some projects have a trigger on auth.users that cleans up or logs when a user goes. If it fails, the delete fails with "Database error deleting user". List the triggers on that table:
select tgname, pg_get_triggerdef(oid) from pg_trigger
where tgrelid = 'auth.users'::regclass and not tgisinternal;
Look for one with DELETE in its definition. In our test, a trigger function that wrote to a public table failed with "permission denied for table deleted_users": Supabase Auth works through its own database role, which can't write to your tables. Make the function run with its owner's rights:
alter function public.on_user_deleted() security definer set search_path = '';
After that, the delete worked and the trigger logged it. With search_path empty, the function must name every table with its schema, like public.deleted_users.
4. Files in Storage
If the message names storage.objects or storage.buckets, the user still owns files. Supabase's docs say to delete that user's files, or give them to another user, before deleting the user.
Soft delete is not a fix
Calling supabase.auth.admin.deleteUser() from the browser fails earlier, with "User not allowed": it needs your secret key, so it belongs on your server or in an Edge Function.
supabase.auth.admin.deleteUser(id, true) soft-deletes. In our test it succeeded despite the blocking key, because the row stays in auth.users, with its email replaced by a scrambled value and deleted_at set. Your rows keep pointing at that row, so use it only if that's what you want.
If an AI tool built your app
Give your AI tool this prompt:
Write a SQL migration for the foreign keys in the public schema that reference auth.users(id): use ON DELETE CASCADE for tables that only hold that user's own data (profiles, settings), and ON DELETE SET NULL, with the column made nullable, for rows that must be kept (orders, invoices). Do the same for foreign keys that reference those tables. List every change and wait for my OK before applying it. Don't change anything else.
Read its list before you say yes: a cascade deletes those rows along with the user, for good.
Not quite your error?
- Deleting a row of your own table fails with "update or delete on table … violates foreign key constraint": Supabase "violates foreign key constraint" (23503).
- Creating a user fails, not deleting: Database error saving new user (Supabase): find the real error and fix sign-up.
- Your app's own delete query fails with "permission denied": Supabase "permission denied for table" (42501) since October 30: the safe fix.
Still stuck?
Open the Auth logs in your dashboard at the time of the failed delete. The entry for the delete request carries the database's own error, with the table or function to fix, even when the answer only said "Database error deleting user". In our test it read ERROR: permission denied for table deleted_users (SQLSTATE 42501).
Other Supabase problems? See Supabase fixes.