# Violation of Primary key Histo

**URL:** <https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [January 30, 2025, 2:11pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616 "2025-01-30T14:11:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ha99](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@Ha99](https://forum.inductiveautomation.com/u/Ha99)\
**Post date:** [January 30, 2025, 2:11pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616/1 "2025-01-30T14:11:22Z")

</div>

Hello,  
I have this error **java.sql.BatchUpdateException: Violation of PRIMARY KEY constraint 'PK\_\_sqlt\_dat** when I restart my opc connection in production or when the trial in demo restarts, I don't know if it's due to a bad setting of the history at the tag level or other things?  
When I check in the histo database the id of the tag in the error with the timstamp and the value is already present in the database, I delete the latter from the database but when restarting I still have the same error

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/d/4d84e2ee8996c1ac4d54d26e33c7cc35f6f68062.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 30, 2025, 2:51pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616/2 "2025-01-30T14:51:23Z")

</div>

Run a query on PK\_\_sqlt\_dat to return the count of each key and order by key descending. There should only be one of each.

---

<div class="post-metadata">

**Author:** ![Ha99](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@Ha99](https://forum.inductiveautomation.com/u/Ha99)\
**Post date:** [January 30, 2025, 2:54pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616/3 "2025-01-30T14:54:21Z")

</div>

When I export the quarantined file, I have all the histo tags in the xml file

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 30, 2025, 3:06pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616/4 "2025-01-30T15:06:27Z")

</div>

So, do you have any duplicates in the primary key1 column?

1 A primary key should contain an integer unique to that row. It can be used to uniquely identify a row and for indexing purposes to greatly speed up queries.

---

<div class="post-metadata">

**Author:** ![Ha99](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@Ha99](https://forum.inductiveautomation.com/u/Ha99)\
**Post date:** [January 30, 2025, 3:09pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616/5 "2025-01-30T15:09:14Z")

</div>

Yes all the export data of the XML file, is already in the Histo database, so duplication of primary kay, because the tagid has the same value and timstamp as in the database.  
but I don't know why, every time there is an insertion in the database even if it's already hitorized in the screen  
No need for chatGPT answer please !

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 30, 2025, 3:41pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616/6 "2025-01-30T15:41:05Z")

</div>

> [@Ha99](#):
>
> all the export data of the XML file, is already in the Histo database

If they are already in the \_HISTO database then you can delete the quarantined file.

> [@Ha99](#):
>
> No need for chatGPT answer please !

I don't use ChatGPT, thank you!

---

<div class="post-metadata">

**Author:** ![Ha99](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@Ha99](https://forum.inductiveautomation.com/u/Ha99)\
**Post date:** [January 30, 2025, 3:42pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616/7 "2025-01-30T15:42:53Z")

</div>

> [@Transistor](#):
>
> quarantined

I don't want to delete the quarantined 20 times a day, I think there's a mistake somewhere

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [January 30, 2025, 6:31pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616/8 "2025-01-30T18:31:03Z")

</div>

You'll need to provide more information about how the tag(s) is set up, and where it originates. (e.g. are you using Ignition's OPC server is there a third party server involved.) Are the gateway and database on separate servers? If not are the two servers set to the same Date and Time format and Location?

Honestly the only ways I've seen the historian give a primary key collision is when there is a discrepancy in the date and time of where the OPC Server is and where the Database is. Or when history is being manually inserted via script.

---

<div class="post-metadata">

**Author:** ![Ha99](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@Ha99](https://forum.inductiveautomation.com/u/Ha99)\
**Post date:** [January 30, 2025, 7:20pm UTC](https://forum.inductiveautomation.com/t/violation-of-primary-key-histo/101616/9 "2025-01-30T19:20:54Z")

</div>

The tags that cause problems are the opc tag, collected via a KEPServerEX, for The database, yes it's in another machine.  
The history is not manual, there is no script or another part for historization.  
Thanks for the help.  
but I don't understand that this only happens if there is a connection after a loss of connection with keep !  
Are there any leads on the subject
