Skip to content

Backups

"cannot drop table because other objects depend on it" in Supabase

"cannot drop table because other objects depend on it" names what CASCADE would remove. Read the list before you drop anything.

Vlad Tkachenko11 min read
A brick wall ringed in amber dashes, with a shelf hung on it, a bolt into the table beside it and a cord to a lock.

In short

  • "cannot drop table because other objects depend on it" (Postgres code 2BP01) means a view, a foreign key or a policy still needs the table. Each DETAIL line names one, and nothing was dropped.
  • CASCADE removes everything on that list: a view entirely, a foreign key from the other table while its rows stay, and a policy on another table, which can leave that table showing nobody any rows.
  • Copy the database, save the definitions you want back, drop each dependent by name, then drop the table without CASCADE. Functions and your app's own code are not on the list, so search them as well.

You asked Lovable, Cursor or Claude Code to remove a table you stopped using, or pressed Delete on it in Supabase's Table Editor, and it is still there. Postgres says why:

ERROR:  2BP01: cannot drop table members because other objects depend on it
DETAIL:  view member_counts depends on table members
policy Members can read projects on table projects depends on table members
constraint invites_member_id_fkey on table invites depends on table members
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

"cannot drop table because other objects depend on it" means other parts of your database are built on that table, and Postgres will not remove it while they are. Nothing was dropped. Each DETAIL line names one of those parts: here a view, a policy on your projects table and a foreign key on invites.

The hint says to add CASCADE, and so does the usual answer you will find for this message. CASCADE does exactly what the hint says. It drops the table, every object on that list and anything built on those, and it does not show you the list again first. It leaves the rows in your other tables alone. What it removes is quieter, and in this example one line decides whether anybody can still see their projects. Read the list before you add the word.

What does "cannot drop table because other objects depend on it" mean?

It means Postgres keeps a record of which objects are built on which, and at least one object still needs the table you asked it to drop. Postgres calls these dependent objects, and it refuses the drop rather than break them.

Picture the table as a wall. Other parts of your database are fixed to it. A view, which is a saved query that reads the table, is a shelf hung on the wall. A foreign key on another table, the rule that each of its rows must point at a real row in this one, is the latch on the next room's door. A policy on another table that looks people up in this one is the list a doorman next door checks before letting anyone in. Postgres will not take the wall down while anything is still fixed to it, and the DETAIL lines are the list of what is.

PartExampleWhat it tells you
Code2BP01Postgres's code for this error, named dependent_objects_still_exist in its list of codes
ERRORcannot drop table members because …The table you asked to drop
DETAILview member_counts depends on table membersOne line for each object that needs the table. Past 100 lines Postgres stops and adds "and … other objects (see server log for list)"
HINTUse DROP ... CASCADE to drop the dependent objects too.Postgres's suggestion, and the line to read last

The wording comes from the code that works out what a drop would remove, and every line has the same shape: the object, "depends on", then your table. A plain drop table already takes the table's own indexes, triggers and constraints with it, as Postgres's page on DROP TABLE says, and the table's own policies go the same way. So the list only holds things that belong to other objects.

If you pressed Delete in the Table Editor, the dialog has a box labelled "Drop table with cascade?", described as "Deletes the table and its dependent objects". Left empty, the drop stops at this error. Ticked, it runs CASCADE. The dialog does not say which objects those are, so the error is the only place you see them.

What does DROP TABLE CASCADE delete?

The table and all its rows, every object on the DETAIL list, and then anything built on those, in turn. What happens to each object depends on what kind it is.

  • A view goes entirely. Postgres's documentation says "CASCADE will remove a dependent view entirely", and a view built on that view goes with it. Any page in your app that reads member_counts gets an error where its numbers were.
  • A foreign key goes, and its table stays. The same page says "in the foreign-key case it will only remove the foreign-key constraint, not the other table entirely." So invites keeps every row, and each still holds a member_id, which now points at nothing and is checked by nothing.
  • A policy on another table goes. A policy records what its using and with check clauses read, in the code that creates it. Here projects lets a person read a project when members holds a row for them. With that policy gone and Row Level Security still on, projects gets what Postgres's chapter on row security calls "a default-deny policy", where "no rows are visible or can be modified", unless another policy lets people read it. Your app keeps running, and every user's project list comes back empty.

In the wall picture: the shelf comes down with the wall, the latch is unscrewed and the next room keeps everything in it, and the doorman's list goes, so the door next door opens for nobody.

A policy created as restrictive works the other way round. Postgres combines ordinary policies with OR and restrictive ones with AND, so dropping a restrictive one lets through rows it used to hold back.

For views, foreign keys and policies, CASCADE deletes no rows outside the table you named. A DETAIL line that names a whole table, or a column of one, is the exception: CASCADE removes that table or column with the data in it.

CASCADE takes the view whole, unscrews the foreign key and leaves its table full, and removes the policy, after which nobody can read a project.

CASCADE tells you what it removed only once it has removed it: each object comes back as a notice beginning "drop cascades to". on delete cascade is a different setting with a similar name. Written on a foreign key, it deletes rows in one table when the row they point at is deleted, and the post on deleting users covers it.

What does the list leave out?

Functions, and your app's own code. Postgres lists only what it has recorded. For a function whose body is written as a block of text, the usual as $$ … $$ form, it records what goes in and what comes out, and nothing about the tables the body reads. Its chapter on dependency tracking says of one such function that Postgres "will not drop the function if the table is dropped."

In a Supabase project the one that matters most is the sign-up trigger. Supabase's guide to managing user data adds a function, handle_new_user, that copies every new sign-up into public.profiles. Drop profiles and no DETAIL line mentions it. With nothing else built on profiles, the drop goes through with no error at all. The next person who signs up gets "Database error saving new user", because the trigger writes into a table that is no longer there, and the same guide warns that "If the trigger fails, it could block signups". The post on that error goes through the fix.

Your app's code is the other half. Every .from('members') in it keeps asking for the table and gets "Could not find the table … in the schema cache" back, which the post on "relation does not exist" explains.

So search both before you drop. For functions, run this in the SQL Editor with your table's name in place of members:

select p.oid::regprocedure as function_name
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'public'
  and p.prosrc ilike '%members%';

pg_proc is Postgres's list of functions, and prosrc holds each one's body as text, so this finds every function in the public schema whose code mentions the word. Change the schema if yours live elsewhere. For your app, search its code for the table's name. In a project synced to GitHub, GitHub's search finds every .from('members') at once.

Nothing Postgres recorded needed profiles, so the drop went through. The function that writes into it was never on the list, and the first sign-up after the drop is where it fails.

How do I drop the table without CASCADE?

Take each object on the list off by name, then drop the table on its own. Without CASCADE the error works as a checklist: Postgres keeps refusing until you have decided about every line, and when the drop goes through there is nothing left for it to take.

1. Make a copy of the database. On the Free plan Supabase keeps no backups of its own. Its backups page says "We automatically back up all Pro, Team, and Enterprise Plan projects on a daily basis", so on Free the copy is yours to make, and the post on Free plan backups shows how without a terminal.

2. Save the definition of anything you want back. Each of these prints what Postgres would need to build it again:

select pg_get_viewdef('public.member_counts'::regclass, true);

select pg_get_constraintdef(oid)
from pg_constraint
where conname = 'invites_member_id_fkey';

select policyname, permissive, roles, cmd, qual, with_check
from pg_policies
where tablename = 'projects';

pg_get_viewdef gives the view's query and pg_get_constraintdef the foreign key's rule. pg_policies lists each policy on the table with its using clause in qual and its with check clause in with_check.

3. Drop or replace each dependent by name, then the table. In one transaction, so a mistake leaves everything as it was:

begin;
drop view public.member_counts;
alter table public.invites drop constraint invites_member_id_fkey;
drop policy "Members can read projects" on public.projects;
drop table public.members;
commit;

There is no CASCADE on the last line. If something was missed, the drop fails again with a new DETAIL line naming it, and the transaction keeps nothing.

If members is being replaced rather than removed, create the new policy on projects before you drop the old one, so the table always has a policy that lets the right people in. If your builder writes the migration for you, read it for the word cascade before it runs; when an agent has already run one, the post on an AI agent deleting your data covers what can come back.

CASCADE is the right call when every line on the list is something you meant to remove anyway, such as a view you made only for this table.

I already ran CASCADE. Can I get it back?

Not from Postgres. A committed drop has no undo, and each object comes back only from wherever it was written down.

  • The list of what went. If your tool showed the notices, every "drop cascades to" line names one object. Copy them before you close the tab.
  • The views and policies. If your project keeps migration files, usually in a supabase/migrations folder, the create view and create policy that made each one are in there.
  • The foreign key. Add it again once the rows it checks point at real rows. Rows that point at nothing make the new rule fail with the error in the post on "violates foreign key constraint".
  • The rows of the dropped table. Only from a copy. On Pro and above, Supabase's daily backup takes the database back to that day. Its backups page says "The project is inaccessible during this process", and that "you could still lose a day's worth of data". On Free there is no Supabase copy to restore.

Of everything here, the copy is the one thing you cannot make after the drop. Reeve Care keeps one of your Supabase database on a schedule, outside your Supabase account, so the table, its rows and the views and policies that went with it are in the copy from before.

Before you drop the next table

Keep a copy from before the drop, and hear about it when a change to your database breaks a page.

Reeve Care keeps a copy of your Supabase database:

  • an encrypted copy on a schedule, on Reeve's own storage in the EU, outside your Supabase account
  • the last copy before a drop holds the table, its rows, and the views and policies CASCADE took with it
  • each copy verified before it counts, by counting the rows in every table
  • every verified copy downloads as a standard zip with the structure and every row, so a definition you need is written down
  • a one-click restore, with a safety copy of the current state taken first
  • your uploaded files as well, once you connect a Storage credential
  • everything Monitor does

See what Care keeps

Reeve Monitor keeps checking from outside:

  • whether your app answers, every 60 seconds, and up to 10 more pages you choose, read for the words that must be there
  • an alert by email, Telegram, Slack or webhook when the app goes down or a page breaks
  • the full security check every hour, including how many rows a visitor with no login can count in the tables your app reads
  • a monthly report on your app, written for you

See what Monitor checks

The free scan shows what a visitor with no login can count in your tables today. About 20 seconds, and no account.

Scan your app free in 20 seconds

What to do now

What to do

  • Read every DETAIL line. Each one names an object that needs the table, and nothing has been dropped yet.
  • Search your functions and your app's code for the table's name. Neither is on the list.
  • Copy the database, and save the definitions of the views, foreign keys and policies you want back.
  • Drop or replace each dependent by name, a new policy before the old one goes, then drop the table without CASCADE, all in one transaction.
  • Add CASCADE only when every line on the list is something you meant to remove.

Start with the DETAIL lines, because they are everything Postgres knows CASCADE would take. If the table holds rows anybody needs, keep a copy of the database from before you drop it.

FAQ

What does cannot drop table because other objects depend on it mean?

It means other objects in your database are built on the table, so Postgres refused to drop it and changed nothing. Each DETAIL line under the error names one: usually a view that reads the table, a foreign key on another table that points at it, or a policy on another table that looks rows up in it. The code is 2BP01.

Does DROP TABLE CASCADE delete rows in other tables?

Not for the objects you will usually see. A foreign key is removed from the other table and that table keeps every row. A view is dropped entirely, but a view holds no rows of its own. A policy on another table is dropped, which can stop people seeing rows they could see before. A DETAIL line that names a whole table or a column is the exception, and CASCADE removes that with its data.

How do I see what CASCADE will drop?

Run the drop without CASCADE and read the DETAIL lines. Postgres's own documentation gives that advice. The list leaves out functions whose body reads the table and your app's own code, so search both for the table's name as well.

Can I undo DROP TABLE CASCADE?

Not inside Postgres. The views and policies come back from wherever they are written down, such as your migration files. The rows of the dropped table come back only from a copy. Supabase keeps daily backups on Pro, Team and Enterprise, none on Free, and restoring one takes the database back to that day.

Is DROP TABLE CASCADE the same as ON DELETE CASCADE?

No. On delete cascade is a setting on a foreign key that deletes rows in one table when the row they point at is deleted. Drop table cascade removes objects that depend on a table you are dropping, such as views, foreign keys and policies.

Written by

Vlad Tkachenko

Founder, Reeve

I spend my time looking at apps built with Lovable, Bolt, v0, Cursor and Replit, and at the short list of mistakes that keep turning up in them.

More about the author

Read next

All articles

Back up your Supabase database before your next change

Reeve keeps an encrypted copy on a schedule and restores it for you if something breaks.

See Supabase backups

Automated external check, not a full audit. Absence of findings is not a guarantee of safety.