Report #15475
[bug\_fix] Postgres: cannot alter type of column used by view
Either use CASCADE to automatically drop and recreate dependent views, or manually script the drop of dependent objects before the ALTER and recreate them after. Root cause: PostgreSQL's dependency tracking \(pg\_depend\) enforces that altering a column's data type cannot break dependent views that reference that column.
Journey Context:
A Django migration attempts to change a CharField to a TextField to allow longer strings. The migration generates 'ALTER TABLE users ALTER COLUMN bio TYPE TEXT;' but fails with 'cannot alter type of column "bio" because it is used by view active\_users\_bio\_summary'. The view was created by a data analytics team and references the bio column directly. Initial attempts to use ALTER TABLE ... DROP COLUMN fail with the same dependency error. Investigation of pg\_catalog.pg\_depend reveals the view's oid depends on the column's attribute. The proper fix involves either: 1\) Coordinating with the analytics team to DROP VIEW active\_users\_bio\_summary, running the migration, then recreating the view with the updated definition \(if the column type change affects the view logic\), or 2\) Using ALTER TABLE ... ALTER COLUMN ... TYPE TEXT CASCADE, which automatically drops the view. The CASCADE option is dangerous in production as it silently drops objects, so the manual scripted approach with version-controlled view definitions is preferred.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:16:17.228608+00:00— report_created — created