ASPX templates
Version 5.x > ASPX templates > Exception thrown when using the CMS.TreeEngine.RelationshipProvider.AddRelationship() Method View modes: 
User avatar
Certified Developer 9
Certified Developer 9
jkh80 - 2/22/2010 2:32:12 PM
   
Exception thrown when using the CMS.TreeEngine.RelationshipProvider.AddRelationship() Method
I have written a utlitiy for a site that I'm working on that imports a large amount of product information into Kentico and adds nodes to the content tree.

The import works fine, but now I am attempting to also create relationships to other nodes once each of the products has been created/updated.

I am attempting to use the CMS.TreeEngine.RelationshipProvider.AddRelationship() method after creating a product node, as follows:


RelationshipProvider.AddRelationship(productCategoryId, product.NodeID, 1);


When I try to use this method, I get the following Exception:

Exception Details: System.Exception: [DataConnection.ExecuteQuery]: Query: INSERT INTO CMS_Relationship ( [RightNodeID],[LeftNodeID], [RelationshipNameID], [RelationshipCustomData] ) VALUES ( @RightNodeID,@LeftNodeID, @RelationshipNameID, @RelationshipCustomData); SELECT SCOPE_IDENTITY() AS [LeftNodeID]: caused exception: The INSERT statement conflicted with the FOREIGN KEY constraint "FK__CMS_Relat__LeftN__151B244E". The conflict occurred in database "RemeeKentico", table "dbo.CMS_Tree", column 'NodeID'.
The statement has been terminated.

Any ideas?