# Support deleting a user but keeping their posts

**URL:** <https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153>\
**Category:** Feature\
**Created:** [March 26, 2014, 4:01pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153 "2014-03-26T16:01:02Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![lightyear](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@lightyear](https://meta.discourse.org/u/lightyear)\
**Post date:** [March 27, 2014, 3:46pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/6 "2014-03-27T15:46:45Z")

</div>

> [@Naatan](#):
>
> In my particular use-case this was necessary as the user signed up twice with similar data causing a bug to be triggered in Discourse (which has since been resolved).

This sounds like a real edge case to me. I’d personally prefer the way that “disabling” vs. “deleting” is supposed to work. And as you say yourself:

> [@Naatan](#):
>
> In an ideal setting where everything goes 100% perfectly you likely wouldn’t ever need to use this functionality

Therefore I’d be against adding it. There is simply no way to anticipate everything that goes wrong and have a feature for every edge in this. It is more work to do that than fix manually the few times it happens. I’ll just quote [xkcd](http://xkcd.com/1205/) on that:

![](https://global.discourse-cdn.com/meta/original/3X/7/c/7c53f8975b588598c45df274586af24e6b9482b9.png)

That said, I’m happy to help you out. Here is a little script that you can copy paste into the rails console (start with `bundle exec rails c` from within your discourse install directory) to re-assign all posts of the soon-to-be-deleted-user to the new\_user:

```ruby
USERNAME_TO_BE_DELETED = "jessamyn"
NEW_USERNAME = "clay_7"
new_user = User.find_by_username(NEW_USERNAME)
old_user = User.find_by_username(USERNAME_TO_BE_DELETED)
posts = old_user.posts
topics = old_user.topics

posts.each do |post|
  post.user = new_user
  post.save()
end

topics.each do |topic|
  topic.user = new_user
  topic.save()
end

```

And you are safe to delete the old user. Be aware, some caches will still show the old data. Also: never copy-paste code into a production systems console that you’ve found on a forum 😉 – Code comes without any warranty.

---

_[View the full topic](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153)._
