# Can't restore to new site: "first\_unread\_topic\_for" already exists with same argument types

**URL:** https://meta.discourse.org/t/cant-restore-to-new-site-first-unread-topic-for-already-exists-with-same-argument-types/63396
**Category:** Support
**Created:** [25 mei 2017 om 21:39 UTC](https://meta.discourse.org/t/cant-restore-to-new-site-first-unread-topic-for-already-exists-with-same-argument-types/63396 "2017-05-25T21:39:40Z")
**Posts on this page:** 5
**Page:** 1

<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: [25 mei 2017 om 21:39 UTC](https://meta.discourse.org/t/cant-restore-to-new-site-first-unread-topic-for-already-exists-with-same-argument-types/63396/1 "2017-05-25T21:39:40Z")

</div>

I’m trying to restore a backup to a new site. It’s failed with this error:

```plaintext
[2017-05-25 21:35:33] EXCEPTION: An error has occurred, this and all later migrations canceled:

PG::DuplicateFunction: ERROR: function "first_unread_topic_for" already exists with same argument types
: CREATE FUNCTION first_unread_topic_for(user_id int)
    RETURNS timestamp AS
    $$
    SELECT COALESCE(first_topic_unread_at, 'epoch'::timestamp)
    FROM users u
    JOIN user_stats ON user_id = u.id
    WHERE u.id = $1
    $$
    LANGUAGE SQL STABLE

```

---

<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: [25 mei 2017 om 22:04 UTC](https://meta.discourse.org/t/cant-restore-to-new-site-first-unread-topic-for-already-exists-with-same-argument-types/63396/2 "2017-05-25T22:04:45Z")

</div>

Is this a new change from you @sam?

---

<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: [25 mei 2017 om 22:11 UTC](https://meta.discourse.org/t/cant-restore-to-new-site-first-unread-topic-for-already-exists-with-same-argument-types/63396/3 "2017-05-25T22:11:02Z")

</div>

Looks like it. It’s in [this commit](https://github.com/discourse/discourse/commit/29fac1ac18acdc1f0d2c1650d33d2d4a1aab0a0b#diff-0039c7e293d24183c852af9cd36ddfea#L30-L40).

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [25 mei 2017 om 22:17 UTC](https://meta.discourse.org/t/cant-restore-to-new-site-first-unread-topic-for-already-exists-with-same-argument-types/63396/4 "2017-05-25T22:17:08Z")

</div>

Its a backup quirk, we don’t move the function out of the schema.

Fixed per:

[https://github.com/discourse/discourse/commit/1a1f5d210137fb8360abab433ca3758e8b371331](https://github.com/discourse/discourse/commit/1a1f5d210137fb8360abab433ca3758e8b371331)

---

<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: [8 juni 2024 om 12:44 UTC](https://meta.discourse.org/t/cant-restore-to-new-site-first-unread-topic-for-already-exists-with-same-argument-types/63396/5 "2024-06-08T12:44:40Z")

</div>

This topic was automatically closed after 2570 days. New replies are no longer allowed.
