I want to update a primary key column, but the change should cascade to all other child tables where this primary key is used as foreign key.

Example: table1 has column "slug" as primary key. One row has the slug "foo" which should be "bar". The table "table1" is used in ten other tables as foreign key (child tables).

I is quite easy to create do it like this:

update table1 ...
update table_child1 ...
update table_child2 ...

Is there a tool to make this easier? For example a tool which looks at the database layout, and creates the update commands.

I use PostgreSQL 9.1, but a portable solution is prefered.

Update: I dont' want/can change the database schema to include "on update cascade" at db level.

2 Answers 2


If your FOREIGN keys are defined with the ON UPDATE CASCADE option, then you need to do nothing more that update the parent table.

But it seems that the ON UPDATE options are not yet properly implemented in Django.


I wrote a management command for my environment (django).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.