Guides & TutorialsTroubleshooting Common ErrorsTroubleshooting a Duplicate entry '0' for key 'PRIMARY' Error

Troubleshooting a Duplicate entry '0' for key 'PRIMARY' Error

Symptom

You may encounter the following error after copying a MySQL database containing WHMCS data to a new location, or restoring a database backup:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' in /path/to/whmcs/vendor/illuminate/database/Connection.php

Cause

This error occurrs when the primary key and auto_increment attributes are absent from one or more tables in the WHMCS database.
Most tables in the WHMCS database will have these attributes on one of the fields.

During the import of the MySQL database table structures at the new location, some data was omitted or an error occurred on the SQL server, resulting in the required structural data failing to copy or restore correctly.

Solution

We recommend dropping the problematic restored database and then working with your server/database administrator for assistance migrating/restoring the database again.

Ensuring that the restoration is performed in such a way as to appropriately restore all the required attributes to the table structure within your WHMCS MySQL database.