# Cannot delete system created topic

**URL:** https://meta.discourse.org/t/cannot-delete-system-created-topic/125781
**Category:** Support
**Created:** [August 14, 2019, 2:26pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781 "2019-08-14T14:26:02Z")
**Posts on this page:** 15
**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: [August 14, 2019, 2:26pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/1 "2019-08-14T14:26:02Z")

</div>

I am trying to remove some categories in favor of using tags, but I end up with one system created topic that I cannot delete (it is Technical in the screenshot, notice the -1 replies). If I try to visit this topic the page freezes and I have to close the tab and start over. Any idea how to delete this, possibly in rails?

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/a/8a1277a3240958cfd376b90f9a268aff2cc2478e.png)

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [August 14, 2019, 2:41pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/2 "2019-08-14T14:41:58Z")

</div>

Try with

```plaintext
cd /var/discourse
./launcher enter app
rails c
Topic.find(id).destroy

```

You will find the `id` placing the mouse over the topic title

 ![image](https://global.discourse-cdn.com/meta/original/3X/3/9/39d401cc8b161192250c5b7f9ce7c5228c323c38.png)

---

<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: [August 14, 2019, 2:59pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/3 "2019-08-14T14:59:34Z")

</div>

Thanks Daniela, that worked to delete the topic, but now when I try to delete the category it still thinks there is one topic and won’t allow me to delete the category. Similar function to delete the category?

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [August 14, 2019, 3:13pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/4 "2019-08-14T15:13:49Z")

</div>

Take a full backup of your site, then try with

```plaintext
cd /var/discourse
./launcher enter app
rails c
rake destroy:topics["Gear","Discussions"]

```

where Gear is your subcategory and Discussions is your parent category.

This should be enough to destroy all the topics in that subcategory. After that you should be able to delete the subcategory.

---

<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: [August 14, 2019, 3:19pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/5 "2019-08-14T15:19:13Z")

</div>

Unfortunately this is the result…

```plaintext
NameError: undefined local variable or method `topics' for main:Object
from (pry):1:in ` __pry__'
[2] pry(main)>

```

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [August 14, 2019, 3:31pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/7 "2019-08-14T15:31:34Z")

</div>

My mistake, try only

```plaintext
cd /var/discourse
./launcher enter app
rake destroy:topics["Gear","Discussions"]

```

---

<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: [August 14, 2019, 3:39pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/8 "2019-08-14T15:39:37Z")

</div>

`There are 0 topics to delete in discussions/gear category` yet I still can’t delete the category `Can't delete this category because topic count is 1.`

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [August 14, 2019, 3:52pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/9 "2019-08-14T15:52:52Z")

</div>

Can you see your logs to see if there are specific errors?

---

<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: [August 14, 2019, 3:55pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/10 "2019-08-14T15:55:32Z")

</div>

No I don’t see anything in the logs related to this…

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [August 14, 2019, 4:11pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/11 "2019-08-14T16:11:09Z")

</div>

Can you try updating the category counters, and see if that helps.

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

```

And then try deleting the category again

---

<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: [August 14, 2019, 8:04pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/12 "2019-08-14T20:04:12Z")

</div>

That returned `nil` unfortunately

---

<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: [August 17, 2019, 7:09pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/13 "2019-08-17T19:09:59Z")

</div>

I was able to reset the topic count using

> `Category.find_by(name: 'Gear').update(topic_count: 0)`

And then was able to delete the category, thanks David!

---

<div class="post-metadata">

### Author: ![Joshua\_Kogan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshua_kogan/32/127595_2.png) [@Joshua\_Kogan](https://meta.discourse.org/u/Joshua_Kogan)
#### Post date: [August 26, 2019, 10:05am UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/16 "2019-08-26T10:05:08Z")

</div>

> [@davidkingham](#):
>
> That returned `nil` unfortunately

This also returned nil for me.

> [@davidkingham](#):
>
> Category.find\_by(name: ‘Gear’).update(topic\_count: 0)

This returned ‘true’, but did not change the -1 values in the reply column of my topics. I also still could not destroy the category.

---

<div class="post-metadata">

### Author: ![Joshua\_Kogan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshua_kogan/32/127595_2.png) [@Joshua\_Kogan](https://meta.discourse.org/u/Joshua_Kogan)
#### Post date: [September 14, 2019, 3:04pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/17 "2019-09-14T15:04:32Z")

</div>

> [@davidkingham](#):
>
> `Category.find_by(name: 'Gear').update(topic_count: 0)`

After spending more time on this, I finally got it to work! Thank you!

---

<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 14, 2019, 3:04pm UTC](https://meta.discourse.org/t/cannot-delete-system-created-topic/125781/18 "2019-10-14T15:04:36Z")

</div>

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