Supabase "Database error deleting user": fix it without losing data

By Arif Khan, AIVolve LLC · Updated November 13, 2026

"I click Delete user in Supabase and get "Failed to delete user: Database error deleting user". Why does that happen, and how do I fix it without losing data?"

Short answer: Supabase Auth tried to delete the user's row in auth.users, and your database refused. Almost always, one of your own tables (usually profiles, sometimes orders, posts or subscriptions) has a foreign key to auth.users with no on delete rule, and Postgres blocks the delete while any row still points at that user. Run the delete once in the SQL editor inside a transaction that is rolled back to see the real error, list every foreign key that points at auth.users, then decide table by table: on delete cascade for data that only describes the person, on delete set null for records you must keep, like orders and invoices. Don't put cascade on everything. It deletes the user's orders and invoices too, and keeps going into tables that point at those.

Why so many founders hit this

Your app works for months, and then the first person asks you to delete their account. You press Delete user in the dashboard and get a one-line error with no table name. An issue on Supabase's GitHub titled with this exact message has 31 comments, most of them some version of "same issue", from December 2024 to April 2026.

I think it catches people because nothing is broken until that moment. A table created with a plain references auth.users works perfectly for sign-ups, logins and every page of your app. It only refuses the first time you try to remove someone.

What the error actually means

Supabase's troubleshooting note lists "Failed to delete user: Database error deleting user" among the errors caused by custom user management logic in your own database. In Supabase Auth's source code, it's the message returned when deleting the user's row from auth.users fails. The dashboard shows only that wrapper. The real reason is in the Postgres error, which looks like this (the example is from Supabase's note):

ERROR:  23503: update or delete on table "users" violates foreign key constraint "profiles_id_fkey" on table "profiles"
DETAIL:  Key (id)=(7428a53c-75b7-4531-9ae9-1567d9c4ac0a) is still referenced from table "profiles".

profiles_id_fkey is the name of the rule, and profiles is the table that's blocking. A foreign key with no on delete rule gets the behavior Postgres calls NO ACTION: as long as any row points at the user, the delete is refused. Supabase's cascade deletes guide says NO ACTION "is the default behavior if you do not specify anything".

Supabase's note lists two other causes: a trigger on auth.users that fails, and Prisma breaking the permissions on auth.users. Step 1 tells you which one you have.

Before you start (2 minutes)

Step 1: See the real error (changes nothing)

Run the same delete that Supabase Auth runs, inside a transaction that is rolled back:

begin;
delete from auth.users where id = 'USER-ID';
rollback;

Postgres stops at the first rule that fails, so this shows one table at a time. Step 2 lists them all at once.

Step 2: List every table that points at your users

This read-only query lists every foreign key from your tables to auth.users and what it does when a user is deleted:

select
  c.conrelid::regclass as table_name,
  c.conname as constraint_name,
  a.attname as column_name,
  a.attnotnull as not_null,
  case c.confdeltype
    when 'a' then 'NO ACTION (blocks the delete)'
    when 'r' then 'RESTRICT (blocks the delete)'
    when 'c' then 'CASCADE (deletes the rows)'
    when 'n' then 'SET NULL (keeps the rows)'
    when 'd' then 'SET DEFAULT'
  end as on_delete
from pg_constraint c
join pg_attribute a
  on a.attrelid = c.conrelid and a.attnum = c.conkey[1]
where c.contype = 'f'
  and c.confrelid = 'auth.users'::regclass
  and c.connamespace <> 'auth'::regnamespace
order by 1, 2;

Every row that says "blocks the delete" will stop a user with rows in that table from being deleted. not_null = true matters later: a column that can't be empty can't use set null.

Now the next level down. If profiles starts cascading, every table that points at profiles is next in line:

select
  c.conrelid::regclass as table_name,
  c.conname as constraint_name,
  c.confrelid::regclass as points_at,
  case c.confdeltype
    when 'a' then 'NO ACTION'
    when 'r' then 'RESTRICT'
    when 'c' then 'CASCADE'
    when 'n' then 'SET NULL'
    when 'd' then 'SET DEFAULT'
  end as on_delete
from pg_constraint c
where c.contype = 'f'
  and c.confrelid in (
    select conrelid from pg_constraint
    where contype = 'f'
      and confrelid = 'auth.users'::regclass
      and connamespace <> 'auth'::regnamespace
  )
order by 3, 1;

A table here with NO ACTION will block the delete again once its parent cascades. One with CASCADE will be deleted along with it.

To see how many rows point at one user before you change anything (still read-only):

select
  c.conrelid::regclass as table_name,
  a.attname as column_name,
  (xpath('/row/n/text()', query_to_xml(format(
    'select count(*) as n from %s where %I = %L',
    c.conrelid::regclass, a.attname, 'USER-ID'
  ), false, true, '')))[1]::text::int as rows_for_this_user
from pg_constraint c
join pg_attribute a
  on a.attrelid = c.conrelid and a.attnum = c.conkey[1]
where c.contype = 'f'
  and c.confrelid = 'auth.users'::regclass
  and c.connamespace <> 'auth'::regnamespace
order by 1;

Step 3: If step 1 named a function, check triggers on auth.users

Supabase's note says a trigger on auth.users can cause the same error. List yours:

select tgname as trigger_name,
  tgfoid::regproc as function_name,
  tgenabled as enabled
from pg_trigger
where tgrelid = 'auth.users'::regclass
  and not tgisinternal;

A function you or your AI builder added (for example one that copies new users into profiles, or cleans up after a delete) shows up here. The Postgres log line from step 1 names the function that failed. Fix or remove that function before you change any foreign keys. Supabase's troubleshooting note walks through trigger problems.

Step 4: Decide per table: cascade, set null or keep blocking

What the table holds Rule What happens when the user is deleted
Only the person: profile, settings, private drafts on delete cascade The rows are deleted with the account
Records you must keep: orders, invoices, payments, audit logs on delete set null The rows stay, and the user column becomes empty
Shared content: posts, comments in other people's threads your choice set null keeps the content from a "deleted user"; cascade removes it
Anything you want a person to look at first leave no action The delete is refused while those rows exist

Supabase's own user management guide says to specify on delete cascade when a profiles table references auth.users. For a profile, that's right. The trouble starts when the same words go on every table.

On our test database, after putting cascade on every foreign key, deleting one user also deleted their 2 orders and, through profiles, their 2 invoices. Nothing warned us. If you might need those records for accounting or refunds, that's data you can't get back without a backup.

Two catches with set null:

set null also doesn't remove personal details stored in the rows you keep, like a name or an address on an order. Decide whether to clear those too.

Step 5: Change the rules safely

You can't edit the on delete rule of an existing foreign key. You drop it and add it back with the new rule. Put the drop and the add in one alter table statement, and the whole change in one transaction, so there's no moment without the rule. Here's the migration we tested, for profiles (cascade), orders (keep, set null) and invoices, which points at profiles:

begin;

-- Data that only describes the person: delete it with the account
alter table public.profiles
  drop constraint profiles_id_fkey,
  add constraint profiles_id_fkey
    foreign key (id) references auth.users (id) on delete cascade;

-- Records you must keep: keep the row, clear the link to the user
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;

-- Invoices point at profiles, which now cascade, so they need a rule too
alter table public.invoices
  alter column profile_id drop not null;
alter table public.invoices
  drop constraint invoices_profile_id_fkey,
  add constraint invoices_profile_id_fkey
    foreign key (profile_id) references public.profiles (id) on delete set null;

commit;

Use your own table, column and constraint names from step 2. On our test database, after this migration plus the same cascade rule on user_settings and set null on posts, deleting the test user removed their profile and settings, kept both orders and both invoices with an empty user column, and removed their sessions.

Tables with many rows. Adding a foreign key normally checks every existing row while it holds a lock on both tables, and one of them is auth.users. On a big table, add the rule with not valid so the existing rows aren't checked during the change, then check them afterwards with validate constraint, which Postgres runs with a lighter lock:

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 not valid;

alter table public.orders
  validate constraint orders_user_id_fkey;

On our test database the new on delete rule worked for deletes right away, before the validate step ran. Most small apps don't need this. Use the first migration.

New tables. Ask your AI builder to always say what happens on delete when a table points at a user:

create table public.notes (
  id bigint generated always as identity primary key,
  user_id uuid not null references auth.users (id) on delete cascade,
  body text
);

On projects covered by Supabase's October 30 change, new tables also need grants before your app can use them. Here's that fix.

Another option: keep the account row (soft delete)

If you'd rather not delete any rows yet, Supabase Auth can soft delete a user. Run this on your server, with the secret key (never in the browser):

const { error } = await supabase.auth.admin.deleteUser(userId, true);

The second argument is shouldSoftDelete. In Supabase Auth's source code, a soft delete keeps the user's row in auth.users, so none of your foreign keys fire. Instead, it clears the email, phone, password and metadata, marks the user as deleted, and removes their sessions and MFA factors. The supabase-js reference says soft deletion "is not reversible".

Your own tables keep everything, including personal details. Clear what you don't need, for example:

update public.profiles
set full_name = null, avatar_url = null
where id = 'USER-ID';

Don't rely only on a deleted_at column in your own tables. Supabase's docs warn that marking an account deleted only in your application tables "leaves the auth.users row intact, so it can still authenticate and refresh."

How to know you're done

A prompt for Lovable, Cursor or Claude Code

Supabase user deletion fails with "Database error deleting user". Fix it without losing data. Work in two phases. Phase 1, read-only: list every foreign key in my database that points at auth.users(id), and every foreign key that points at those tables. For each one show the table, column, constraint name, current ON DELETE rule and whether the column is NOT NULL. Also list any triggers on auth.users. For each table, tell me what it stores and recommend ON DELETE CASCADE (data that only describes the user, like profiles and settings), ON DELETE SET NULL (records I must keep, like orders, invoices and payments) or keeping NO ACTION. Show me the list and change nothing. Phase 2, after I approve: write ONE migration that, for each table I approved, drops the foreign key and adds it back with the new ON DELETE rule in the same ALTER TABLE statement, and first drops NOT NULL on any column that will use SET NULL. Do not use CASCADE on orders, invoices, payments, subscriptions or audit logs. Do not delete or update any rows. Do not change anything in the auth schema. Show me the migration before applying it.

FAQ

What does "Database error deleting user" mean in Supabase?+

Supabase Auth tried to delete the user's row in auth.users and your database refused. Usually a table such as profiles has a foreign key to auth.users with no on delete rule, so Postgres blocks the delete while rows still point at that user. A failing trigger on auth.users can cause it too. The Postgres logs show the exact cause.

Should I add ON DELETE CASCADE to every table that references auth.users?+

No. Cascade deletes the user's rows in that table, and in every table that cascades from it. Use it for data that only describes the person, like profiles and settings. For orders, invoices and payments you need to keep, use ON DELETE SET NULL, and make sure the column allows null.

How do I change an existing foreign key to ON DELETE CASCADE in Supabase?+

Drop the constraint and add it back with the new rule in one statement, for example: alter table public.profiles drop constraint profiles_id_fkey, add constraint profiles_id_fkey foreign key (id) references auth.users (id) on delete cascade; List the foreign keys that point at auth.users first to get the exact constraint names.

Can I delete a Supabase user but keep their orders?+

Yes. Change the foreign key on orders to ON DELETE SET NULL and drop NOT NULL on that column. The orders stay, with an empty user column. Or soft delete the user from your server with auth.admin.deleteUser(id, true), which keeps the auth.users row so no foreign key fires.

Can I just delete the user's profile row by hand first?+

That works for one user, but the next deletion fails the same way, and tables that point at profiles can block it or lose data. Fixing the on delete rules once is safer than deleting rows by hand.

Want a second pair of eyes?

Start with a free X-ray: 2 minutes, no code or passwords. Your AI builder writes a read-only report that includes security red flags, and an AIVolve developer reviews every X-ray within 1 business day. Get a free X-ray →

Related: Supabase columns users should never edit · Supabase RLS for AI-built apps: the 10-minute check · Supabase "permission denied for table" after Oct 30 · Security audit prompts for AI-built apps

Written by Arif Khan, AIVolve LLC. VibeCoderSOS isn't affiliated with Supabase. Docs were checked and every SQL block was tested on a local Postgres database on November 13, 2026.

Need help?

Start with a free X-ray: 2 minutes, no code or passwords. Your AI builder writes a read-only report that includes security red flags, and an AIVolve developer reviews every X-ray within 1 business day.

Get a free X-ray →