# 升级在重复键错误（"在帖子ID和URL MD5上索引帖子热链媒体"）时失败

**URL:** https://meta.discourse.org/t/upgrade-fails-on-duplicate-key-error-index-post-hotlinked-media-on-post-id-and-url-md5/226002
**Category:** Bug
**Created:** [2022 年5 月 3 日 15:34 UTC](https://meta.discourse.org/t/upgrade-fails-on-duplicate-key-error-index-post-hotlinked-media-on-post-id-and-url-md5/226002 "2022-05-03T15:34:51Z")
**Posts on this page:** 1
**Showing post:** 8

<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: [2022 年5 月 3 日 19:31 UTC](https://meta.discourse.org/t/upgrade-fails-on-duplicate-key-error-index-post-hotlinked-media-on-post-id-and-url-md5/226002/8 "2022-05-03T19:31:57Z")

</div>

在我的开发实例上，数据库迁移成功了，但如果我从 `2022-04-27-153103-v20220407195246.tar.gz` 恢复备份，则会失败：

```plaintext
                                                                                [361/9020]
正在迁移数据库... EXCEPTION: /home/pfaffman/src/discourse-repos/discourse/lib/discourse.rb:126:in `exec': 数据库迁移失败。
忽略 /home/pfaffman/src/discourse-repos/discourse/db/schema_cache.yml，因为它已过期。当前模式版本是 20220407195246，但模式缓存文件中的版本是 20220428094027。
rake aborted!
StandardError: 发生错误，此迁移及之后的所有迁移均已取消：

```

后面还有更多内容，其中包含：

```
ActiveRecord::StatementInvalid: PG::DuplicateObject: ERROR: type \"hotlinked_media_status\" already exist

```

---

_[View the full topic](https://meta.discourse.org/t/upgrade-fails-on-duplicate-key-error-index-post-hotlinked-media-on-post-id-and-url-md5/226002)._
