- The foreign keys are not being updated to point to the new table.
You started out okay with your test script, but the pg_depend bit needs work. I would recommend examining that table closely until you have a really good understanding of how it works - both on the objid and refobjid side. Create and modify tables and see how the pg_depend entries change. Hint: Try it with and without foreign keys.