Tricky condition for PostgreSQL UPDATE query
Just add an ON DELETE CASCADE option to your foreign key:

ALTER TABLE links_link 
DROP CONSTRAINT constraint_name,   
ADD CONSTRAINT constraint_name FOREIGN KEY (latest_reply_id)
      REFERENCES links_publicreply(id) ON DELETE CASCADE;


Apparently in django the above is translated as:

on_delete=models.CASCADE