# “discourse\_solved\_solved\_topics” 在重建过程中违反非空约束

**URL:** <https://meta.discourse.org/t/discourse-solved-solved-topics-violates-not-null-constraint-during-rebuild/391813>\
**Category:** Support\
**Tags:** solved\
**Created:** [2025年十二月20日 18:30 UTC](https://meta.discourse.org/t/discourse-solved-solved-topics-violates-not-null-constraint-during-rebuild/391813 "2025-12-20T18:30:38Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)\
**Post date:** [2025年十二月21日 07:03 UTC](https://meta.discourse.org/t/discourse-solved-solved-topics-violates-not-null-constraint-during-rebuild/391813/6 "2025-12-21T07:03:12Z")

</div>

感谢 @pfaffman 和 @JammyDodger，我将深入研究数据库以尝试修复此问题。

使用数据浏览器，我获得了有问题行的列表，我们可以看到这在时间上非常有限，也许是该时间段内插件出现了一些问题？

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/a/3/aa39d0a02901fad942a6b0631c6dc03e5bd12ee8.png)

我看到了这个提交，它试图修复一个类似的问题？

> <https://github.com/discourse/discourse-solved/commit/1805184cde87d2621f1252612f142f4bbbf03a79>
>
> We are seeing some errors when migrating and adding indexes on \`answer\_post\_id\`.…
> 
> \`\`\`
> \#\<StandardError:"An error has occurred, all later migrations canceled:\\n\\nPG::UniqueViolation: ERROR: could not create unique index \\"index\_discourse\_solved\_solved\_topics\_on\_answer\_post\_id\\"\\nDETAIL: Key (answer\_post\_id)=(13006) is duplicated.\\n"\>
> \`\`\`
> 
> This PR modifies the earlier migration, and also adds one before the addition of indexes to remove duplicates.

无论如何都很有趣。我会花时间修复它，因为它非常敏感。

---

_[View the full topic](https://meta.discourse.org/t/discourse-solved-solved-topics-violates-not-null-constraint-during-rebuild/391813)._
