Unique Contraint Critical Error // 1062 Duplicate entry - Help

Your software
My Mautic version is: 4.4.4
My PHP version is: 7.4

Your problem
My problem is:

Using the tracking script we are seeing a 500 error when trying to associate anonymous user to known user and give tags to that user

These errors are showing in the log:

[2023-05-03 07:07:05] mautic.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\UniqueConstraintViolationException: "An exception occurred while executing 'INSERT INTO lead_tags_xref (lead_id, tag_id) VALUES (?, ?)' with params ["962459", 77]:  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '962459-77' for key 'PRIMARY'" at /var/www/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 74 {"exception":"[object] (Doctrine\\DBAL\\Exception\\UniqueConstraintViolationException(code: 0): An exception occurred while executing 'INSERT INTO lead_tags_xref (lead_id, tag_id) VALUES (?, ?)' with params [\"962459\", 77]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '962459-77' for key 'PRIMARY' at /var/www/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:74, Doctrine\\DBAL\\Driver\\PDO\\Exception(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '962459-77' for key 'PRIMARY' at /var/www/mautic/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '962459-77' for key 'PRIMARY' at /var/www/ams/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117)"} {"hostname":"my-hostname","pid":1894640}

Is this maybe because of the INSERT into lead_tags and could it be fixed with changing this to an update?
Just shooting in the dark here, so any direction is gladly welcomed

Hi, no this means that given contact with id 962459 is already associated with tag that has id 77 and so mysql server does not allow an insert with the same value.

The combination of lead_id and tag_id can only occur once in the table.