# Error moving posts (solved)

**URL:** https://meta.discourse.org/t/error-moving-posts-solved/29582
**Category:** Support
**Created:** [June 3, 2015, 4:51am UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582 "2015-06-03T04:51:19Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [June 3, 2015, 4:51am UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/1 "2015-06-03T04:51:19Z")

</div>

I’m seeing this on one of the discourse I manage, when trying to move two posts to a new topic

```plaintext
ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_topic_users_on_topic_id_and_user_id"
DETAIL: Key (topic_id, user_id)=(266, 177) already exists.
: INSERT INTO topic_users(user_id, topic_id, notification_level, notifications_reason_id)
           SELECT user_id, 266, 3, 6
             FROM category_users
            WHERE notification_level = 3
              AND category_id = 24
              AND NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = 266 AND user_id = category_users.user_id)
)

```

I’ve upgraded to latest, and still see it.

What can I do here?

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [June 3, 2015, 6:35am UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/2 "2015-06-03T06:35:34Z")

</div>

confirmed that after a full docker rebuild, the error persists

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 3, 2015, 6:42am UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/3 "2015-06-03T06:42:41Z")

</div>

Anything weird about those posts? Are you moving the first post?

I can’t repro a problem with moving posts on [try.discourse.org](http://try.discourse.org).

1. Pick random topic
2. Move 2 bottom posts to a new topic
3. Succeeds

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 3, 2015, 6:51am UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/4 "2015-06-03T06:51:57Z")

</div>

Total guess: that user (one whose posts you are moving) doesn’t have permission to be in that category?

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [June 4, 2015, 3:20am UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/5 "2015-06-04T03:20:07Z")

</div>

I wondered, but now I’m getting the same error on another forum I manage

This is what I get on discourse v1.3.0.beta11 +23

![](https://global.discourse-cdn.com/meta/original/3X/2/9/295c75cda0bd6a75cbf1b010df239fb38c663fac.png)

```plaintext
ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_topic_users_on_topic_id_and_user_id"
DETAIL: Key (topic_id, user_id)=(1325, 567) already exists.
: INSERT INTO topic_users(user_id, topic_id, notification_level, notifications_reason_id)
           SELECT user_id, 1325, 3, 6
             FROM category_users
            WHERE notification_level = 3
              AND category_id = 6
              AND NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = 1325 AND user_id = category_users.user_id)
)

```

I get this when I try to approve a post in the `Known Issues` Category on my other forum.. that forum has no category restrictions at all.

```plaintext
ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_topic_users_on_topic_id_and_user_id"
DETAIL: Key (topic_id, user_id)=(1327, 567) already exists.
: INSERT INTO topic_users(user_id, topic_id, notification_level, notifications_reason_id)
           SELECT user_id, 1327, 3, 6
             FROM category_users
            WHERE notification_level = 3
              AND category_id = 6
              AND NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = 1327 AND user_id = category_users.user_id)
)

```

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [June 4, 2015, 1:27pm UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/6 "2015-06-04T13:27:10Z")

</div>

I’ve moved my posts about the errors moving posts to this topic.

I’d call it a bug, but there is a chance that this would be due to the default actions I have in our postgres databases. Those are all user based though… if new user, set some prefs, and add watched categories.

We don’t have anything effecting categories or permissions.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [June 4, 2015, 2:04pm UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/7 "2015-06-04T14:04:03Z")

</div>

> [@watchmanmonitor](#):
>
> there is a chance that this would be due to the default actions I have in our postgres databases

What kind of default actions?

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [June 4, 2015, 3:49pm UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/8 "2015-06-04T15:49:47Z")

</div>

I set users’ defaults:

[https://github.com/watchmanmonitoring/discourse\_user\_importer/wiki/Column-Defaults:-Set-default-mailing-list-settings](https://github.com/watchmanmonitoring/discourse_user_importer/wiki/Column-Defaults:-Set-default-mailing-list-settings)

I set users’ watch lists

[https://github.com/watchmanmonitoring/discourse\_user\_importer/wiki/Triggers:-Edit-users-watch-lists-on-creation](https://github.com/watchmanmonitoring/discourse_user_importer/wiki/Triggers:-Edit-users-watch-lists-on-creation)

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [June 7, 2015, 9:16pm UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/9 "2015-06-07T21:16:53Z")

</div>

This is still going on in my forum… Am I the only one experiencing this?

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [June 8, 2015, 5:24am UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/10 "2015-06-08T05:24:07Z")

</div>

This was indeed our auto-watch.

the command ended up double-adding watch categories to one of our users. we’ve updated the watch script to help prevent this.. but it was no issue with discourse proper

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 8, 2015, 6:31am UTC](https://meta.discourse.org/t/error-moving-posts-solved/29582/11 "2015-06-08T06:31:50Z")

</div>


