Interesting… we are missing a dependant destroy here, I am not sure why.
Easy to fix though
Post.where('topic_id not in (select id from topics)').limit(100).destroy_all
And repeat… till no results.