Report #14313
[bug\_fix] cannot drop table X because other objects depend on it - dependency blocking DDL
Use DROP ... CASCADE to automatically drop dependent objects \(views, foreign keys, functions\), or manually drop dependencies in reverse dependency order before dropping the target.
Journey Context:
You run a Rails or Django migration to drop a legacy table during a schema cleanup. The migration fails with 'ERROR: cannot drop table orders because other objects depend on it'. You query the database with 'SELECT \* FROM information\_schema.view\_table\_usage WHERE table\_name='orders'' and find a view 'monthly\_revenue' depends on it. You also check 'SELECT \* FROM information\_schema.referential\_constraints WHERE unique\_constraint\_table\_name='orders'' and find a foreign key from 'order\_items'. You initially try 'DROP TABLE orders', which fails. You consider manually dropping the view and the foreign key constraint first, which works but is tedious. The better fix is using 'DROP TABLE orders CASCADE', which tells Postgres to automatically drop all dependent objects \(the view and the foreign key constraint\) in the correct order. However, use with caution in production as it might drop views you forgot about. Alternatively, if using a migration tool like Flyway or Alembic, you must manually script the dependent drops in reverse dependency order to avoid the CASCADE side effects. The root cause is Postgres's strict dependency tracking preventing accidental data loss through dependent objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:15:47.592470+00:00— report_created — created