This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Violation of PRIMARY KEY constraint when adding new file using Batch Loader

parepalli - Saturday, May 24, 2014 1:08 PM:

 I am  editing a part, creating part bom relationship, creating part and adding file relationship using Batch Loader. I don't understand why "PRIMARY KEY" constraint will occur when a new file is added. Can anybody please help me with this error?

 

[1:35:24 AM]: Start batch load

[ *** Worker process for lines 2 - 2 *** ]:
[1:35:24 AM - Worker process for lines up to 1 (Thread #1)]: Logged in
[1:35:24 AM - Worker process for lines up to 1 (Thread #1)]: #1 - <Item type="Part" where="name='LO' and  classification = 'Outfitting Equipment/Group/Detail_Sub_System' and project_number = 'Mar' and is_current='1'" action="edit"><Relationships><Item type="Part BOM" action="add"><related_id><Item type="Part" action="add"><name>/KEY_PLAN</name><classification>Outfitting Equipment/Aveva Drawings/Arrangement</classification><Relationships><Item type="Part Aveva" action="add"><related_id><Item type="Aveva Drawing" action="add"><name>/KEY_PLAN</name><project>Mar</project><mdb>/HADMIN</mdb><module>AVEVA Marine MarineDrafting</module></Item></related_id></Item><Item type="Part File" action="add"><related_id><Item type="File" action="add"><actual_filename>C:ArasAvevaConnector67.dxf</actual_filename><filename>/KEY_PLAjjN.dxf</filename><Relationships><Item type="Located" action="add"><related_id>67BBB9204FE84A8981ED8313049BA06C</related_id></Item></Relationships></Item></related_id></Item></Relationships></Item></related_id></Item></Relationships></Item>
[1:35:25 AM - Worker process for lines up to 1 (Thread #1)]: #1 - <Fault>
[1:35:25 AM - Worker process for lines up to 1 (Thread #1)]:     Code: SOAP-ENV:Server
[1:35:25 AM - Worker process for lines up to 1 (Thread #1)]:     Message: File already exists.
[1:35:25 AM - Worker process for lines up to 1 (Thread #1)]:     Details: File already exists.Violation of PRIMARY KEY constraint.

[1:35:26 AM]: Finish batch load: succeeded - 0; failed - 1



gks - Monday, May 26, 2014 6:02 AM:

As this is a databas error: have you verified there are no key constrainst set on the database?



Brian - Monday, May 26, 2014 6:45 AM:

The issue here is in this line:

<related_id><Item type="File" action="add"><actual_filename>C:ArasAvevaConnector67.dxf</actual_filename><filename>/KEY_PLAjjN.dxf</filename><Relationships><Item type="Located" action="add"><related_id>67BBB9204FE84A8981ED8313049BA06C</related_id></Item></Relationships></Item></related_id></Item></Relationships></Item></related_id>

As this is an "add" action and the "related_id" is specified, if the script is run twice then this will cause the primary key violation.

Either change the "add" to "create" or drop the "related_id" value.

Brian.