Integrity constraint violation: 1062 Duplicate entry '2147483647' for key 'tblinvoices.PRIMARY' Errors

Symptom

Performing an action that creates an invoice (including the daily automation cron tasks or when your staff or a client places an order) you may observe an Oops!  Integrity constraint violation error message.

The full error is:

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

Cause

The Invoice Starting # setting is an integer value that is larger than 2,147,483,648 (2 billion 100 thousand), which is higher than MySQL® can accommodate.

To assign a custom invoice numbering format, see Configuring a Custom Invoice Number Format.

Solution

1. Using a tool like phpMyAdmin, perform the following query against WHMCS's MySQL database and note the result:

SELECT MAX(invoiceid) + 1 FROM tblinvoiceitems;
MySQL Reuslt showing a value of 4

2. Log in to the WHMCS Admin Area.

3. Go to the Invoices tab at Configuration > System Settings > General Settings.

4. Enter the value that you noted in step 1 for Invoice Starting #.

5. Click Save Changes.

Invoice Starting # will be empty after saving. This is normal.