# 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:** 1
**Showing post:** 5

<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!
> 
> ```

---

_[View the full topic](https://meta.discourse.org/t/cannot-delete-tag-with-2k-topics/252326)._
