# Cannot delete tag with 2k topics

**URL:** https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326
**Category:** Support
**Created:** [January 19, 2023, 6:07pm UTC](https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326 "2023-01-19T18:07:11Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![davidkingham](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/davidkingham/32/119528_2.png) [@davidkingham](https://meta.discourse.org/u/davidkingham)
#### Post date: [January 19, 2023, 6:07pm UTC](https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326/1 "2023-01-19T18:07:11Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [January 21, 2023, 11:31am UTC](https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326/2 "2023-01-21T11:31:22Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![davidkingham](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/davidkingham/32/119528_2.png) [@davidkingham](https://meta.discourse.org/u/davidkingham)
#### Post date: [January 21, 2023, 6:34pm UTC](https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326/3 "2023-01-21T18:34:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Tealk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tealk/32/525923_2.png) [@Tealk](https://meta.discourse.org/u/Tealk)
#### Post date: [September 24, 2024, 9:28am UTC](https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326/4 "2024-09-24T09:28:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [September 25, 2024, 3:16pm UTC](https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326/5 "2024-09-25T15:16:49Z")

</div>

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](https://meta.discourse.org/t/administrative-bulk-operations/118349).

* * *

1. for each tag, enter the rails console:

```plaintext
cd /var/discourse
./launcher enter app
rails c

```

1. find and remove the tag from it’s topics

```plaintext
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.
> 
> ```plaintext
> t = Tag.find_by_name('your_tag_name')
> t.destroy!
> 
> ```

---

<div class="post-metadata">

### Author: ![Tealk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tealk/32/525923_2.png) [@Tealk](https://meta.discourse.org/u/Tealk)
#### Post date: [September 25, 2024, 3:31pm UTC](https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326/6 "2024-09-25T15:31:52Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [October 25, 2024, 3:32pm UTC](https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326/7 "2024-10-25T15:32:05Z")

</div>

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