Forum OpenACS Q&A: Re: can't delete an acs_object -> ERROR: update or delete on "acs_objects" violates foreign key constraint "acs_objects_context_id_fk" on "acs_objects"

The problem here is not directly related to comments though - it is related to the context that comments are in.

The acs_objects table has a context_id field which references object_id field in itself; this field is set for general comments for them to inherit permission from an object in a different hierarchy (the content folder that I am dealing with). When deleteing the cr_folder hierarchy, the comments are not part of the same hierarchy, so the CASCADE does nothing for them, however since the context_id still references the objects, the delete fails.

The right thing may be to set on delete cascade on context_id, but then a delete of an object in one hierarchy may cause deletes in others. in this case this is the correct thing to do (comments should get erased with the objects they are tacked on to) but I am not sure that this is true in the general case.