Error Enforcing Referential Integrity Because Relationship: “Contains values that reference one or more non-existent items in the target list”

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/4691

  •  16-10-2019
  •  | 
  •  

Question

When I try to enforce referential integrity like this:

fieldLookup.Indexed = true;
fieldLookup.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.Restrict
fieldLookup.Update()

It works for most, but not all of the fields in my app. When it fails it looks like this:

Microsoft.SharePoint.SPException: This lookup column cannot enforce a relationship behavior because it contains values that reference one ore more non-existent items in the target list. 
---> System.Runtime.InteropServices.COMException (0x810705B0): 
<nativehr>0x810705b0</nativehr><nativestack></nativestack>This lookup column cannot enforce a relationship behavior because it contains values that reference one ore more non-existent items in the target list.
  at Microsoft.SharePoint.Library.SPRequestInternalClass.UpdateField(String bstrUrl, String bstrListName, String bstrXML)
  at Microsoft.SharePoint.Library.SPRequest.UpdateField(String bstrUrl, String bstrListName, String bstrXML)
  --- End of inner exception stack trace ---
  at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
  at Microsoft.SharePoint.Library.SPRequest.UpdateField(String bstrUrl, String bstrListName, String bstrXML)
  at Microsoft.SharePoint.SPField.UpdateCore(Boolean bToggleSealed)
  at Microsoft.SharePoint.SPField.Update()
  at MyApp.Features.Service.EntityBuilder.EntityBuilderBase.EnforceReferentialIntegrity()

Incidentally, I get this exact same error when click "Enforce relationship behavior" in the properties of the field in the browser.

I've looked in Reflector, but this error is happening in unmanaged code, so I'd be just as happy if anyone could provide any additional debugging techniques.

Thanks, - Lee

Was it helpful?

Solution

Do the lists have items in them already? This works best when setting up up two empty lists.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top