# Can't delete a user's posts: InvalidForeignKey

**URL:** https://meta.discourse.org/t/cant-delete-a-users-posts-invalidforeignkey/398175
**Category:** Support
**Created:** [March 11, 2026, 2:53pm UTC](https://meta.discourse.org/t/cant-delete-a-users-posts-invalidforeignkey/398175 "2026-03-11T14:53:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 11, 2026, 2:53pm UTC](https://meta.discourse.org/t/cant-delete-a-users-posts-invalidforeignkey/398175/1 "2026-03-11T14:53:59Z")

</div>

I triggered a user’s posts deletion.

Since the posts weren’t deleted, I looked at sidekiq and `/logs`. The deletion process returns an error:

```plaintext
Job exception: PG::ForeignKeyViolation: ERROR: update or delete on table "reviewables" violates foreign key constraint "fk_rails_2fe5fa5cd0" on table "reviewable_notes"
DETAIL: Key (id)=(7870) is still referenced from table "reviewable_notes".

```

This reviewable item was approved 15 days ago and there are indeed three notes attached to it.

The user who created the flag id 7870 is also the user I’m trying to delete the posts of, which I guess is the issue.

But what do I do now to get rid of this error and delete the user’s account?

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [March 11, 2026, 3:21pm UTC](https://meta.discourse.org/t/cant-delete-a-users-posts-invalidforeignkey/398175/2 "2026-03-11T15:21:32Z")

</div>

Looks like this is a bug and at the moment you need to delete the comment:

> [@User deletion problem, returns "Error 500" on delete all posts](https://meta.discourse.org/t/user-deletion-problem-returns-error-500-on-delete-all-posts/397700/3):
>
> Thanks! Your guess was spot on. User had few flagged posts by moderators and one of them had a note added. After deleting the note I could then successfully delete user all users posts and user it self. By the way, is the bug already fixed in default branch? Maybe it’s time for updates. EDIT: note on version/build for reference of any others that maybe encounter similar issue: v2026.1.0-latest mid-January container build on default tests-passed branch.

---

<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: [April 10, 2026, 3:22pm UTC](https://meta.discourse.org/t/cant-delete-a-users-posts-invalidforeignkey/398175/3 "2026-04-10T15:22:27Z")

</div>

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