Cannot delete tag with 2k topics

I think there are two ways to remove those tags from their associated topics in the rails console, one being “softer” than the other. It’s a good idea to do a backup first - see here about doing rails commands: Administrative Bulk Operations.


  1. for each tag, enter the rails console:
cd /var/discourse
./launcher enter app
rails c
  1. find and remove the tag from it’s topics
tag_name = "your_tag_name"   # Replace with your tag name
tag = Tag.find_by(name: tag_name)
Topic.joins(:tags).where(tags: { name: tag_name }).each do |topic|
  topic.tags.delete(tag)
  topic.save
end
  1. repeat for second tag
  2. then you should be able to remove those tags via the UI

Alternate faster method that is riskier (I would do the above way myself)

But instead of step 2 and 4, I think you can also do this for each tag after entering the rails console.

t = Tag.find_by_name('your_tag_name')
t.destroy!
3 Likes