# \`discourse remap\` failed

**URL:** https://meta.discourse.org/t/discourse-remap-failed/144763
**Category:** Self-hosting
**Created:** [March 19, 2020, 12:38am UTC](https://meta.discourse.org/t/discourse-remap-failed/144763 "2020-03-19T00:38:12Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [March 19, 2020, 12:38am UTC](https://meta.discourse.org/t/discourse-remap-failed/144763/1 "2020-03-19T00:38:12Z")

</div>

I just moved a forum from `name.com` to `forum.name.com` but it failed:

> Error: ERROR: duplicate key value violates unique constraint “unique\_post\_links”  
> DETAIL: Key (topic\_id, post\_id, url)=(246, 813, [http://forum.name.com](http://forum.name.com)) already exists.  
> The remap has only been partially applied due to the error above. Please re-run the script again.

So I ran it again (it failed again) then did `rake posts:rebake` and checked the forum to find I have some instances of `forum.forum.name.com`. (So then do `discourse remap forum.forum.name.com forum.name.com` and `rake posts:rebake` to try and fix it - with some success, I had to change some instances manually).

I have some questions:

- Does `discourse remap name.com forum.name.com` only apply to post content? If not, is it just Site Settings I need to look through to find possible issues?
- Should it be run in some sort of transaction? (If so, it didn’t appear to when it failed for me)

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [March 19, 2020, 3:27am UTC](https://meta.discourse.org/t/discourse-remap-failed/144763/2 "2020-03-19T03:27:48Z")

</div>

> [@AstonJ](#):
>
> Does `discourse remap name.com forum.name.com` only apply to post content?

No, it applies to the entire database. Posts, site settings, themes, uploads, everything.

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [March 19, 2020, 3:56am UTC](https://meta.discourse.org/t/discourse-remap-failed/144763/3 "2020-03-19T03:56:08Z")

</div>

Ah yeah looking at the full error again now it seems to have gone through these:

```plaintext
backup_metadata=1
categories=6
email_logs=306
email_tokens=1
groups=1
incoming_domains=3
incoming_emails=3
javascript_caches=4
post_custom_fields=275
post_revisions=134
posts=441
post_search_data=50
search_logs=8
site_settings=5
stylesheet_cache=540
theme_fields=9
theme_settings=3

```

I’ve checked all site settings and they’re fine (as are themes) and I guess all the above were done - can you see anything that should have been done that wasn’t? Do you think it is safe to continue as is or do you think it needs to be redone from scratch?

Also any ideas why `duplicate key value violates unique constraint` errors are becoming more frequent on Discourse? I’ve noticed a few topics on this and I think this is the third time I’ve had such an issue myself.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [March 19, 2020, 4:05am UTC](https://meta.discourse.org/t/discourse-remap-failed/144763/4 "2020-03-19T04:05:36Z")

</div>

> [@AstonJ](#):
>
> can you see anything that should have been done that wasn’t?

Not from the output, no. We only output tables with changes. No way to know if a table not in the list because it of the error, or simply because there were no instances of `name.com` in the (not listed) table.

> [@AstonJ](#):
>
> Also any ideas why `duplicate key value violates unique constraint` errors are becoming more frequent on Discourse?

Unfortunately that’s beyond my expertise.

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [March 19, 2020, 4:23am UTC](https://meta.discourse.org/t/discourse-remap-failed/144763/5 "2020-03-19T04:23:23Z")

</div>

Thanks Joshua.

Any ideas what the numbers signify? Number of changes?

What is the recommended way forward now? Fix the unique constraint error then reverse (go from `forum.name.com` back to `name.com`, then back again) or do something else?

**Edit** : done

I entered the app and Rails console then deleted the `TopicLink` in question then went from `forum.name.com` back to `name.com`, then back again.

```plaintext
backup_metadata=1
categories=6
email_logs=318
email_tokens=2
groups=1
incoming_domains=3
incoming_emails=3
javascript_caches=4
post_custom_fields=277
post_revisions=140
posts=444
post_search_data=51
search_logs=10
site_settings=5
stylesheet_cache=564
theme_fields=9
theme_settings=3
topic_links=281
topics=30
topic_search_data=8
translation_overrides=1
uploads=54
user_auth_token_logs=48
user_emails=2
user_histories=189
Done

```

---

<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: [March 18, 2024, 11:18am UTC](https://meta.discourse.org/t/discourse-remap-failed/144763/6 "2024-03-18T11:18:41Z")

</div>



---

<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: [March 18, 2024, 1:12pm UTC](https://meta.discourse.org/t/discourse-remap-failed/144763/7 "2024-03-18T13:12:45Z")

</div>


