Unable to create object in Plesk: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry for key 'PRIMARY'

Created:

2017-05-16 22:46:47 UTC

Modified:

2017-08-08 13:17:51 UTC

1

Was this article helpful?


Have more questions?

Submit a request

Unable to create object in Plesk: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry for key 'PRIMARY'

Applicable to:

  • Plesk for Linux

Symptoms

Attempt to create customer or subscription fails with:

Error: DB query failed: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '129' for key 'PRIMARY'

And the second part of the error is the exact failed query, e.g.:

replace sys_users set `id`='0', `serviceNodeId`='1', `login`='example.com', `home`='/var/www/vhosts/example.com', `shell`='/bin/false', `quota`='0', `account_id`='653', `mapped_to`=NULL" 

Cause

AUTO_INCREMENT value for the table is lower than real MAX id value.

Resolution 

1. Create a backup of Plesk database:
#mysqldump psa -uadmin -p`cat /etc/psa/.psa.shadow` > psa_current.sql
2. Find the last ID value in table from error in our case it would be sys_users:
#plesk db "SELECT MAX(id) from sys_users;"
+---------+
| MAX(id) |
+---------+
| 81      |
+---------+
3. Adjust AUTO_INCREMENT value with the MAX(id) + 1 in affected table from error:
#plesk db "ALTER TABLE sys_users AUTO_INCREMENT = 82;"

4. Now operation should be completed successfully.

Have more questions? Submit a request
Please sign in to leave a comment.