# Unique Contraint Critical Error // 1062 Duplicate entry - Help

**URL:** <https://forum.mautic.org/t/unique-contraint-critical-error-1062-duplicate-entry-help/27889>\
**Category:** Product Support\
**Created:** [May 3, 2023, 7:59am UTC](https://forum.mautic.org/t/unique-contraint-critical-error-1062-duplicate-entry-help/27889 "2023-05-03T07:59:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [May 3, 2023, 7:59am UTC](https://forum.mautic.org/t/unique-contraint-critical-error-1062-duplicate-entry-help/27889/1 "2023-05-03T07:59:10Z")

</div>

**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:

```auto
[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

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [May 3, 2023, 9:45am UTC](https://forum.mautic.org/t/unique-contraint-critical-error-1062-duplicate-entry-help/27889/2 "2023-05-03T09:45:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [January 11, 2024, 8:54am UTC](https://forum.mautic.org/t/unique-contraint-critical-error-1062-duplicate-entry-help/27889/3 "2024-01-11T08:54:14Z")

</div>

This seems to be a re-occrung problem . is there a way around this ?

When I am trying to send a simple email it is throwing this error.

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [January 11, 2024, 4:36pm UTC](https://forum.mautic.org/t/unique-contraint-critical-error-1062-duplicate-entry-help/27889/4 "2024-01-11T16:36:22Z")

</div>

You are probably doing this within campaign and somehow manipulating the tags of the contact.

I do not think email sending as such does anything connected to tags.

This is really not a solution, but you could try to remove the FK constraint on lead\_tags table.

Anyway, I am inerrested in resolving this the right way - which means figuring out why/where you are trying to insert duplicated combinations of the keys.
