Hacker News new | ask | show | jobs
by premchai21 5101 days ago
But, last I checked, you could PRAGMA foreign_keys=off temporarily, which would also inhibit the automatic handling of foreign key constraints in other tables when the target table is renamed or dropped. Then you can create a new table, populate it, drop the old one, rename the new one to the old name, and turn foreign_keys back on, and the constraints will now target the new table.
1 comments

Does that actually work for dropping and renaming tables? I thought I tried that.
In any event you can get the foreign keys from sqlite_master, delete them during the reorganisation and then put them back afterwards.
It does in 3.7.13 (and presumably older versions, but I don't have a solid record of this immediately available).