Cannot delete tag with 2k topics

I am cleaning up some tags and have had no issue until this tag which has 2400 topics attached to it. I get the generic “Sorry, an error has occurred.” and nothing in the logs. Can I delete this in the backend or anything else I can try? It does not have special characters, it’s simply ig

Thanks all!

It should be possible to delete it through the rails console, but you could try bulk removing it from batches of topics first to try and do it more cleanly through the UI?

Thanks, but I don’t see anyway to do this in bulk. I can remove all tags, but there’s no option to remove a single tag when topics have multiple tags.

I am looking for a way to delete 2 tags, one has 5818 entries and the other 1604.
These are the ones that come from a xenforo import and are not needed.

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

Thank you very much, it worked at the first attempt. I chose the first way and then deleted the tags via the UI when they were no longer assigned anywhere.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.