# Can't delete topic without category

**URL:** https://meta.discourse.org/t/cant-delete-topic-without-category/367811
**Category:** Support
**Created:** [May 27, 2025, 6:19pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811 "2025-05-27T18:19:10Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![steinjer](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@steinjer](https://meta.discourse.org/u/steinjer)
#### Post date: [May 27, 2025, 6:19pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/1 "2025-05-27T18:19:10Z")

</div>

I’ve a topic in our database with an category\_id which category someone has deleted. I can open this topic directly with it’s id:  
url: …/t/3

in table topics the id = 3 has category = 4. But this category is deleted and not in table categories. Many of this lost topics I could delete. But this one doesn’t work, cause attribute closed and archived are true.

If I choose in popup menu “Permanently Delete” this topic, I get error message:  
“An error occurred: This topic has undeleted posts. Please permanently delete them before permanently deleting the topic.”

Any idea how to insert a dummy category with id 4 in database or to delete this lost topic?

---

<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: [May 27, 2025, 7:03pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/2 "2025-05-27T19:03:32Z")

</div>

> [@steinjer](#):
>
> in table topics the id = 3 has category = 4.

I think that’s the About topic for the #General category?. Normally the about topics would be undeletable in the UI.

Is there a reason you want to delete this one completely?

---

<div class="post-metadata">

### Author: ![steinjer](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@steinjer](https://meta.discourse.org/u/steinjer)
#### Post date: [May 27, 2025, 7:17pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/3 "2025-05-27T19:17:48Z")

</div>

cause this category isn’t more available, but which is more important: link to all categories in sidebar doesn’t work anymore.  
If I try open …/categories I get errormessage: “Error Something went wrong.” and in browser console errormessage is shown:

```plaintext
Uncaught TypeError: i is null
    reason binary.js:7
    l item.js:166
    get topic.js:1017
    ee upload.js:65
    get topic.js:1017
    get topic.js:1017
    eM topic.js:1017
    s backup-codes.js:33
    n backup-codes.js:33
    Z upload.js:65
    T backup-codes.js:33
    evaluate backup-codes.js:33
    _execute backup-codes.js:33
    execute backup-codes.js:33
    rerender backup-codes.js:33
    render theme-setting.js:6
    _renderRoots theme-setting.js:6
    tA backup-codes.js:33
    _renderRoots theme-setting.js:6
    _renderRootsTransaction theme-setting.js:6
    _revalidate theme-setting.js:6
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _run client-error-handler.js:88
    run client-error-handler.js:88
    d bookmark.js:114
    Ember 2
    _join client-error-handler.js:88
    join client-error-handler.js:88
    p bookmark.js:114
    h bookmark.js:114
    $ topic.js:1017
    trigger composer-action-title.js:62
    transitionStarted add-translation.js:27
    loading ace-editor.js:176
    D upload.js:65
    triggerEvent upload.js:65
    trigger form-template-validation.js:54
    _handleSlowTransition upload.js:65
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _runExpiredTimers client-error-handler.js:88
    setTimeout handler*setTimeout client-error-handler.js:88
    _installTimerTimeout client-error-handler.js:88
    _later client-error-handler.js:88
    later client-error-handler.js:88
    T bookmark.js:114
    _triggerAction form-template-validation.js:54
    click form-template-validation.js:54
binary.js:7
Uncaught TypeError: i is null
    reason binary.js:7
    l item.js:166
    get topic.js:1017
    ee upload.js:65
    get topic.js:1017
    get topic.js:1017
    eM topic.js:1017
    s backup-codes.js:33
    n backup-codes.js:33
    Z upload.js:65
    T backup-codes.js:33
    evaluate backup-codes.js:33
    _execute backup-codes.js:33
    execute backup-codes.js:33
    rerender backup-codes.js:33
    render theme-setting.js:6
    _renderRoots theme-setting.js:6
    tA backup-codes.js:33
    _renderRoots theme-setting.js:6
    _renderRootsTransaction theme-setting.js:6
    _revalidate theme-setting.js:6
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _run client-error-handler.js:88
    run client-error-handler.js:88
    d bookmark.js:114
    success base.js:71
    l loader.js:1286
    fireWith loader.js:1286
    jQuery 4
    a base.js:71
    e named-references.js:49
    e named-references.js:49
    A base.js:71
    _findCategoriesAndTopics item.js:166
    k named-references.js:49
    w named-references.js:49
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _runExpiredTimers client-error-handler.js:88
    setTimeout handler*setTimeout client-error-handler.js:88
    _installTimerTimeout client-error-handler.js:88
    _later client-error-handler.js:88
    later client-error-handler.js:88
    T bookmark.js:114
    _triggerAction form-template-validation.js:54
    click form-template-validation.js:54

```

```plaintext
TypeError: t.category_list.categories is undefined
    s form-template-validation.js:54
    categoriesFrom form-template-validation.js:54
    _findCategoriesAndTopics item.js:166
    k named-references.js:49
    w named-references.js:49
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _run client-error-handler.js:88
    run client-error-handler.js:88
    d bookmark.js:114
    success base.js:71
    l loader.js:1286
    fireWith loader.js:1286
    jQuery 4
    a base.js:71
    e named-references.js:49
    e named-references.js:49
    A base.js:71
    _findCategoriesAndTopics item.js:166
    k named-references.js:49
    w named-references.js:49
    invoke client-error-handler.js:88
    flush client-error-handler.js:88
    flush client-error-handler.js:88
    _end client-error-handler.js:88
    end client-error-handler.js:88
    _runExpiredTimers client-error-handler.js:88
    setTimeout handler*setTimeout client-error-handler.js:88
    _installTimerTimeout client-error-handler.js:88
    _later client-error-handler.js:88
    later client-error-handler.js:88
    T bookmark.js:114
    _triggerAction form-template-validation.js:54
    click form-template-validation.js:54

```

```plaintext
Error while processing route: discovery.categories t.category_list.categories is undefined 3069/categoriesFrom/s<@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:9:2817
categoriesFrom@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:9:2809
11341/_findCategoriesAndTopics/<@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:27:122623
k@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:441:164470
w@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:441:164363
invoke@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:202:7701
flush@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:202:6778
flush@https://forum.mydiscourse.de/assets/chunk.0144d0b7f03b4dd2b0a0.d41d8cd9.js:202:8650
... and much more

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 27, 2025, 7:27pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/4 "2025-05-27T19:27:11Z")

</div>

It sounds like someone deleted the category when it has topics in it somehow? That’s not supposed to happen. I think you’ll need to do something like

```plaintext
rails c
c=Category.last; # or some other way to get a category)
Topic.where(category_id: 4).update_all(category_id: c.id)

```

---

<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: [May 27, 2025, 7:27pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/5 "2025-05-27T19:27:12Z")

</div>

If your #General category was deleted safely through the UI then it’s expected that the About topic would be soft deleted like you’re seeing. It shouldn’t cause any issues. 🤔

I think there may be something else at play. Is there any more detail about that error in your `/logs` page?

---

<div class="post-metadata">

### Author: ![steinjer](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@steinjer](https://meta.discourse.org/u/steinjer)
#### Post date: [May 27, 2025, 7:50pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/6 "2025-05-27T19:50:51Z")

</div>

> [@pfaffman](#):
>
> `Topic.where(category_id: 4).update_all(category_id: c.id)`

This seems not to work:

```plaintext
discourse(prod)> Topic.where(category_id: 4).update_all(category_id: 20)
=> 0
discourse(prod)> Topic.where(id: 3).update_all(category_id: 20)
=> 0

```

And in [Data Explorer](https://meta.discourse.org/t/32566?silent=true) I get:

```plaintext
Select id, closed, archived, title,category_id
from topics
where id = '3'

result:
id closed archived title category_id
3 true true Über die Kategorie Team 4

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 27, 2025, 7:54pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/7 "2025-05-27T19:54:50Z")

</div>

Hmm. I thought your broken topic had category\_id of 4.

> [@steinjer](#):
>
> in table topics the id = 3 has category = 4.

That was my best guess. If you have a budget you might ask for help in #Marketplace. I think you’ll need someone to get into rails to see if they can figure it out.

---

<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: [May 27, 2025, 8:23pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/8 "2025-05-27T20:23:26Z")

</div>

#Marketplace is always an option, especially if it’s urgent. ❤

Though a bit more detail here might help jimmy up a community response. 🤞

You both seem confident that the root cause is this topic. If [data explorer](https://meta.discourse.org/t/32566?silent=true) can find it then you should be able to find it in the rails console. If you can find it then you should be able to use post\_destroyer on it and delete it from there?

(Though slightly hesitant to recommend it as I’ve not quite connected up the dots to where the issue is)

---

<div class="post-metadata">

### Author: ![steinjer](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@steinjer](https://meta.discourse.org/u/steinjer)
#### Post date: [May 27, 2025, 8:41pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/9 "2025-05-27T20:41:19Z")

</div>

yes, in ruby console I can see that topic:

```plaintext
result = ActiveRecord::Base.lease_connection.exec_query('SELECT id, category_id FROM topics WHERE id = 3')
result.rows
=> [[3, 4]]

```

but in Topic is nothing

```plaintext
Topic.where(id: 3)
=> []

```

---

<div class="post-metadata">

### Author: ![steinjer](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@steinjer](https://meta.discourse.org/u/steinjer)
#### Post date: [May 28, 2025, 6:59am UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/10 "2025-05-28T06:59:56Z")

</div>

> [@JammyDodger](#):
>
> If you can find it then you should be able to use post\_destroyer on it and delete it from there?

as you can see, finding is possible. But I have no idea of the Ruby syntax to delete exactly this one table entry.

---

<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: [May 28, 2025, 7:33am UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/11 "2025-05-28T07:33:14Z")

</div>

Hmm. 🤔 It is unusual to be able to find it one way and not the other.

The rails console can be a bit of a sharp knife so it’d be best to figure out what exactly has gone wrong just to minimise any accidents/knock on effects.

How was this category deleted in the first place?

(Just in case the issue isn’t caused by this stray topic, I’ll throw in the basics of checking [safe mode](https://meta.discourse.org/t/53504?silent=true) and seeing if there’s any more info about the error in your `YourSite/logs` page too)

Though I don’t know if your data is in a state where the category delete catch-all could help? [Bulk delete all topics in a category](https://meta.discourse.org/t/bulk-delete-all-topics-in-a-category/97904)

---

<div class="post-metadata">

### Author: ![steinjer](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@steinjer](https://meta.discourse.org/u/steinjer)
#### Post date: [May 28, 2025, 11:05am UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/12 "2025-05-28T11:05:07Z")

</div>

> [@JammyDodger](#):
>
> How was this category deleted in the first place?

Good question. It was done some years ago by an other admin.

Meanwhile I deleted this topic direct in rails console with:

```plaintext
result = ActiveRecord::Base.lease_connection.exec_delete('DELETE FROM topics WHERE id = 3')

```

After this, topic is deleted 😀

---

<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: [May 28, 2025, 11:25am UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/13 "2025-05-28T11:25:36Z")

</div>

And that solved your wonky category link in the sidebar too?

It’s interesting that it’s only just showing a problem now when it had been happily deleted for a number of years.

If you figure out the connection let me know. 🙂

---

<div class="post-metadata">

### Author: ![steinjer](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@steinjer](https://meta.discourse.org/u/steinjer)
#### Post date: [May 28, 2025, 1:33pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/14 "2025-05-28T13:33:42Z")

</div>

Unfortunately, this does not fix the error with the category link. But the problem with the non-deletable post is solved for now. The category problem is also not logged in the log. I will tackle this in the next few days.

---

<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: [June 27, 2025, 1:34pm UTC](https://meta.discourse.org/t/cant-delete-topic-without-category/367811/15 "2025-06-27T13:34:16Z")

</div>

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