# Проблема PG::UniqueViolation при обновлении до 3.1.0.beta4

**URL:** <https://meta.discourse.org/t/pg-uniqueviolation-problem-during-3-1-0-beta4-upgrade/262163>\
**Category:** Self-hosting\
**Created:** [19.Апрель.2023 01:03:15 UTC](https://meta.discourse.org/t/pg-uniqueviolation-problem-during-3-1-0-beta4-upgrade/262163 "2023-04-19T01:03:15Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![ahmedeldeep](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ahmedeldeep/32/121601_2.png) [@ahmedeldeep](https://meta.discourse.org/u/ahmedeldeep)\
**Post date:** [19.Апрель.2023 01:03:15 UTC](https://meta.discourse.org/t/pg-uniqueviolation-problem-during-3-1-0-beta4-upgrade/262163/1 "2023-04-19T01:03:15Z")

</div>

При обновлении до версии 3.1.0.beta4 возникла следующая ошибка:

```plaintext
I, [2023-04-19T00:02:26.057232 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'LOAD_PLUGINS=0 bundle exec rake plugin:pull_compatible_all'
I, [2023-04-19T00:02:27.340128 #1] INFO -- : discourse-adplugin уже находится в последней совместимой версии
discourse-cakeday уже находится в последней совместимой версии
discourse-formatting-toolbar уже находится в последней совместимой версии
discourse-whos-online уже находится в последней совместимой версии
docker_manager уже находится в последней совместимой версии
vbulletin-bbcode уже находится в последней совместимой версии

I, [2023-04-19T00:02:27.340368 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
2023-04-19 00:02:30.080 UTC [634] discourse@discourse ERROR: duplicate key value violates unique constraint "index_users_on_username"
2023-04-19 00:02:30.080 UTC [634] discourse@discourse DETAIL: Key (username)=(xxx) already exists.
2023-04-19 00:02:30.080 UTC [634] discourse@discourse STATEMENT: UPDATE users SET password_algorithm = '$pbkdf2-sha256$i=64000,l=32$'
	WHERE id IN (
	  SELECT id FROM users
	  WHERE users.password_hash IS NOT NULL
	  AND users.password_algorithm IS NULL
	  LIMIT 5000
	)
	
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_username"
DETAIL: Key (username)=(xxx) already exists.

```

После исправления дублирующихся пользователей появляются новые.

```plaintext
discourse=# REINDEX TABLE users;
ERROR: could not create unique index "index_users_on_username_lower"
DETAIL: Key (username_lower)=(mhm) is duplicated.
discourse=# REINDEX TABLE users;
ERROR: could not create unique index "index_users_on_username_lower"
DETAIL: Key (username_lower)=(ahmedhafez) is duplicated.
CONTEXT: parallel worker
discourse=# REINDEX TABLE users;
ERROR: could not create unique index "index_users_on_username_lower"
DETAIL: Key (username_lower)=(hany) is duplicated.
discourse=# REINDEX TABLE users;
ERROR: could not create unique index "index_users_on_username_lower"
DETAIL: Key (username_lower)=(eng_ali) is duplicated.
CONTEXT: parallel worker
discourse=# REINDEX TABLE users;
ERROR: could not create unique index "index_users_on_username_lower"
DETAIL: Key (username_lower)=(saad_saad) is duplicated.
discourse=# REINDEX TABLE users;
ERROR: could not create unique index "index_users_on_username_lower"
DETAIL: Key (username_lower)=(eng_ali) is duplicated.
CONTEXT: parallel worker
discourse=# REINDEX TABLE users;
ERROR: could not create unique index "index_users_on_username_lower"
DETAIL: Key (username_lower)=(mostafa11) is duplicated.
CONTEXT: parallel worker

```

---

_[View the full topic](https://meta.discourse.org/t/pg-uniqueviolation-problem-during-3-1-0-beta4-upgrade/262163)._
