fhe
(Florian)
March 26, 2025, 6:39am
1
I’m getting this error when trying to update via
./launcher rebuild app
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: could not create unique index "index_discourse_solved_solved_topics_on_answer_post_id" (ActiveRecord::RecordNotUnique)
DETAIL: Key (answer_post_id)=(201795) is duplicated.
Any ideas on how to resolve this issue?
thoka
(Thomas Kalka)
March 26, 2025, 8:00am
3
Delete one of the SolvedTopic
records via rails console:
DiscourseSolved::SolvedTopic.where(answer_post_id:201795).last.destroy
1 Like
fhe
(Florian)
March 26, 2025, 9:16am
4
Thank you. I’ve tried to access those, but I’m getting
NameError: uninitialized constant SolvedTopic
Any other ideas?
fhe
(Florian)
March 26, 2025, 9:32am
5
I’ve now connected to the database directly and deleted the record with the duplicate answer_post_id
from discourse_solved_solved_topics
.
All good now. Thanks again for your quick reply!
1 Like
thoka
(Thomas Kalka)
March 26, 2025, 12:59pm
6
Hm. discourse-solved was updated recently .
There is a chance, that this error was thrown during database migration.
fhe
(Florian)
March 26, 2025, 2:19pm
7
Yes, this happened during database migration.
thoka
(Thomas Kalka)
March 26, 2025, 5:04pm
8
Seems to be fixed with this patch:
committed 02:21PM - 26 Mar 25 UTC
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.
3 Likes
fhe
(Florian)
March 26, 2025, 5:07pm
9
Excellent! Thanks for the heads up — I’ve marked your post as solution.
2 Likes