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 occurs 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 fields for these attributes.
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. This resulted in the required structural data failing to copy or be restored correctly.
Solution
We recommend dropping the problematic restored database and working with your server or database administrator for assistance migrating or restoring the database again.
Ensure that the restoration is performed to appropriately restore all of the required attributes to the table structure within your WHMCS MySQL database.