Report #71304
[bug\_fix] PostgreSQL cannot drop table because other objects depend on it \(SQLSTATE 2BP01\)
The root cause is PostgreSQL's dependency tracking: tables cannot be dropped if views, foreign keys, functions, or triggers reference them. The fix is to either use DROP TABLE ... CASCADE to automatically drop dependent objects \(dangerous, requires knowing what will be dropped\), or manually drop dependent objects in the correct order \(safer for migrations\). Query pg\_depend or use \\d\+ in psql to inspect dependencies.
Journey Context:
A developer runs a migration to drop an obsolete orders\_legacy table during a schema cleanup. The migration fails with 'ERROR: cannot drop table orders\_legacy because other objects depend on it. Detail: view monthly\_sales\_summary depends on table orders\_legacy. Hint: Use DROP ... CASCADE to drop the dependent objects too.' The developer checks and realizes the BI team created a view monthly\_sales\_summary that joins orders\_legacy to customers. The developer is tempted to use CASCADE but realizes this would also drop the view without the BI team knowing. Instead, they coordinate with the BI team to first migrate the view to use orders instead of orders\_legacy, then drop the legacy table. They document the need to check pg\_depend or use a pre-migration script that queries information\_schema.view\_table\_usage to detect dependencies before attempting drops in production.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:15:37.528272+00:00— report_created — created