Report #24450
[bug\_fix] SQLite does not support ALTER TABLE DROP COLUMN \(SQLite migration limitations\)
Execute the 'table rebuild' pattern: create a new table with the desired schema, copy data from the old table with \`INSERT INTO new\_table SELECT ... FROM old\_table\`, drop the old table, and rename the new table to the original name; recreate indexes, triggers, and foreign keys as necessary.
Journey Context:
Developer runs a Django migration to remove a column from a SQLite database. The migration fails with 'django.db.utils.OperationalError: near 'DROP': syntax error'. Investigation reveals that SQLite's ALTER TABLE implementation is intentionally limited for historical reasons: it can add columns \(with restrictions on defaults\) and rename tables, but cannot drop columns, alter column types, or remove constraints in versions prior to 3.35.0 \(and even in newer versions, many ORMs don't support the limited DROP COLUMN syntax\). The developer considers exporting the data, recreating the database, and reimporting, but this is unacceptable for production. Researching SQLite documentation, they discover the canonical 'table rebuild' workaround. They write a migration script that: \(1\) creates a new table 'mytable\_new' with the desired schema \(without the dropped column\), \(2\) copies data with 'INSERT INTO mytable\_new \(col1, col2\) SELECT col1, col2 FROM mytable', \(3\) drops the old table 'DROP TABLE mytable', \(4\) renames 'ALTER TABLE mytable\_new RENAME TO mytable', and \(5\) recreates indexes and foreign keys.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:26:41.272117+00:00— report_created — created