Completely remove deleted topics

The topics were deleted but we can still see them and they are marked as deleted.
The topics do not exist in the topics table but are still showing in the UI.

Example … {host}/t/17533 returns a deleted topic yet the topic has been deleted.

ActiveRecord::RecordNotFound: Couldn't find Topic with 'id'=17533 [WHERE ("topics"."deleted_at" IS NULL)]
from /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.2/lib/active_record/relation/finder_methods.rb:346:in `raise_record_not_found_exception!'
Topic.where('deleted_at is not null')

Topic.where('deleted_at is not null')
=> []

How do you completely remove a deleted topic?

Edit at 2019-01-24 09:23:49

If I undelete the topic I can find it using Topic.where(id:17533).first.
If I then delete it again I can no longer find it using Topic.where(id:17533).first

Where are deleted Topics stored?

Do a search for destroy, there really isn’t much benefit to doing it though. You will have to use the console though to do it. It is not exposed in the UI.

1 Like

We’re deleting topics that were imported incorrectly.

If you used a standard importer, you’ll also want to delete the corresponding CustomPostFields (which you could also use to know which topics and posts to destroy).


We ended up starting with a clean database.

That’s the best thing to do.