Cannot delete system created topic

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?

2 curtidas

Try with

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

3 curtidas

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?

1 curtida

Take a full backup of your site, then try with

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.

2 curtidas

Unfortunately this is the result


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

My mistake, try only

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

2 curtidas

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.

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

1 curtida

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


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

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

And then try deleting the category again

1 curtida

That returned nil unfortunately

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!

4 curtidas

This also returned nil for me.

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.

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

3 curtidas

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