Fix foreign key viaolation when deleting entities.