Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
Since I was still in dev I was able to delete the lists and recreate them and the referential integrity magically worked. So I bet you're right, I bet it's because they were non-empty. –  Anonymous Sep 3 '10 at 19:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.