Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-29 · container image postgres:17
PostgreSQL tracks dependencies between objects and refuses to drop one that others still use. The DETAIL line lists exactly which objects depend on it, so read it first.
The HINT suggests DROP ... CASCADE, which drops the dependent objects too, such as the view or the foreign key constraint. The fixes below instead deal with each dependency explicitly, so you know what is removed.
01Dropping a table that a view uses
View v_order_total selects from orders. DROP TABLE orders fails and DETAIL says view v_order_total depends on table orders.
Setup
CREATE TABLE orders (id int PRIMARY KEY, amount numeric);
CREATE VIEW v_order_total AS SELECT sum(amount) AS total FROM orders;CREATE TABLE
CREATE VIEWDROP TABLE orders;ERROR: 2BP01: cannot drop table orders because other objects depend on it
DETAIL: view v_order_total depends on table orders
HINT: Use DROP ... CASCADE to drop the dependent objects too.SELECT view_name FROM information_schema.view_table_usage WHERE table_name = 'orders'; view_name
---------------
v_order_total
(1 row)DROP VIEW v_order_total;DROP VIEWinformation_schema.view_table_usage lists the views that use the table, here v_order_total. Drop (or rewrite) the view first, then DROP TABLE orders succeeds.
DROP TABLE orders;DROP TABLE02Dropping a column that a view selects
View v_customers selects the fax column. Dropping only that column fails: view v_customers depends on column fax of table customers.
Setup
CREATE TABLE customers (id int PRIMARY KEY, name text, fax text);
CREATE VIEW v_customers AS SELECT id, name, fax FROM customers;CREATE TABLE
CREATE VIEWALTER TABLE customers DROP COLUMN fax;ERROR: 2BP01: cannot drop column fax of table customers because other objects depend on it
DETAIL: view v_customers depends on column fax of table customers
HINT: Use DROP ... CASCADE to drop the dependent objects too.BEGIN;
DROP VIEW v_customers;
ALTER TABLE customers DROP COLUMN fax;
CREATE VIEW v_customers AS SELECT id, name FROM customers;
COMMIT;BEGIN
DROP VIEW
ALTER TABLE
CREATE VIEW
COMMITIn one transaction, drop the view, drop the column, and create the view again without fax. Afterwards customers has only id and name, and the view still exists.
SELECT column_name FROM information_schema.columns WHERE table_name = 'customers' ORDER BY ordinal_position; column_name
-------------
id
name
(2 rows)03Dropping a parent table referenced by a foreign key
orders.customer_id references customers. DETAIL names the constraint: constraint orders_customer_id_fkey on table orders depends on table customers.
Setup
CREATE TABLE customers (id int PRIMARY KEY, name text);
CREATE TABLE orders (id int PRIMARY KEY, customer_id int REFERENCES customers (id));CREATE TABLE
CREATE TABLEDROP TABLE customers;ERROR: 2BP01: cannot drop table customers because other objects depend on it
DETAIL: constraint orders_customer_id_fkey on table orders depends on table customers
HINT: Use DROP ... CASCADE to drop the dependent objects too.ALTER TABLE orders DROP CONSTRAINT orders_customer_id_fkey;ALTER TABLEDrop the foreign key on the child table with the name from DETAIL: ALTER TABLE orders DROP CONSTRAINT orders_customer_id_fkey. The orders table and its rows stay; then DROP TABLE customers succeeds.
DROP TABLE customers;DROP TABLE04DROP ROLE for a user who owns objects or has privileges
When removing an account, DROP ROLE lab_b fails with role "lab_b" cannot be dropped because some objects depend on it. DETAIL lists everything: owner of schema lab_b, owner of table lab_b.my_report, and privileges on lab_a.sales.
Setup
CREATE TABLE sales (id int PRIMARY KEY, amount numeric);
GRANT SELECT ON sales TO lab_b;CREATE TABLE
GRANTCREATE TABLE my_report (id int);CREATE TABLEDROP ROLE lab_b;ERROR: 2BP01: role "lab_b" cannot be dropped because some objects depend on it
DETAIL: owner of schema lab_b
privileges for table lab_a.sales
owner of table lab_b.my_reportREASSIGN OWNED BY lab_b TO lab_a;
DROP OWNED BY lab_b;REASSIGN OWNED
DROP OWNEDREASSIGN OWNED BY lab_b TO lab_a gives the owned objects to another role, and DROP OWNED BY lab_b removes its remaining privileges. Then DROP ROLE lab_b succeeds. Both commands work per database, so run them in each database where the role has objects.
DROP ROLE lab_b;DROP ROLEFAQ
What does cannot drop table because other objects depend on it mean?
A view, a foreign key or another object still uses the table. The DETAIL line lists them. Remove or change those first, or use CASCADE if you are sure they should be dropped too.
Is DROP TABLE ... CASCADE safe?
It also drops the dependent objects, such as views and foreign key constraints. Check the DETAIL list first so you know what will disappear.
How do I drop a PostgreSQL role that owns objects?
Run REASSIGN OWNED BY old_role TO new_role; and DROP OWNED BY old_role;, then DROP ROLE old_role;.
How do I drop a column used by a view in PostgreSQL?
Drop the view, drop the column, and recreate the view without that column, ideally in one transaction.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12