Rake users:merge on former admin account throws error

You can run the following code in the rails console (rails c) to find the offending posts. I’ll leave it up to you what you do with them.

source_user = User.find_by_username("<source username>");

Post.with_deleted.
  where(user_id: source_user.id).
  where("NOT EXISTS (SELECT 1 FROM topics WHERE posts.topic_id = topics.id)")