none
Export-SPWeb Error RRS feed

  • Question

  • Good morning,

    On a particular sub-site I keep encountering issues during the export process and I was curious if anyone else had encountered a similar issue previously.

    During the export process, on a differing document each time I will receive a fatal as below.  If I navigate to the document in question with a browser it will load with no issues.

    FatalError: This constraint cannot be enabled as not all values have corresponding parent values.
    [5/24/2017 5:40:45 PM] Debug:    at System.Data.ConstraintCollection.AddForeignKeyConstraint(ForeignKeyConstraint constraint)
       at System.Data.ConstraintCollection.Add(Constraint constraint, Boolean addUniqueWhenAddingForeign)
       at System.Data.DataRelationCollection.DataSetRelationCollection.AddCore(DataRelation relation)
       at System.Data.DataRelationCollection.Add(DataRelation relation)
       at System.Data.DataRelationCollection.Add(String name, DataColumn parentColumn, DataColumn childColumn)
       at Microsoft.SharePoint.Deployment.FileObjectHelper.GetNextBatch()
       at Microsoft.SharePoint.Deployment.ObjectHelper.RetrieveDataFromDatabase(ExportObject exportObject)
       at Microsoft.SharePoint.Deployment.FileObjectHelper.RetrieveData(ExportObject exportObject)
       at Microsoft.SharePoint.Deployment.ExportObjectManager.GetObjectData(ExportObject exportObject)
       at Microsoft.SharePoint.Deployment.ExportObjectManager.MoveNext()
       at Microsoft.SharePoint.Deployment.SPExport.SerializeObjects()
       at Microsoft.SharePoint.Deployment.SPExport.Run()

    Thursday, May 25, 2017 2:10 PM

All replies

  • Hi Alex,

    The reason for failure was because Allwebparts table had entries for Webparts pointing to pages or their versions that did not exist in AllDocs and AllDocVersions.

    we can use SQL detection query to look at the rows we were going to delete:

    USE WSS_Content; 
    GO
     
    SELECT TOP 1000 * FROM 
    (SELECT tp_ID, 
    tp_PageUrlID, 
    tp_SiteId, 
    tp_IsCurrentVersion, 
    tp_PageVersion, 
    tp_Level 
    FROM TVF_Sites_ALL() AS S 
    CROSS APPLY 
    TVF_AllWebParts_Site(S.Id) AS AWP 
    OUTER APPLY 
    TVF_AllDocs_Id_Level(S.Id,AWP.tp_PageUrlID, AWP.tp_Level) AS AD 
    WHERE AD.Id IS NULL AND AWP.tp_IsCurrentVersion = 1 
    UNION 
    SELECT tp_ID, 
    tp_PageUrlID, 
    tp_SiteId, 
    tp_IsCurrentVersion, 
    tp_PageVersion, 
    tp_Level 
    FROM TVF_Sites_ALL() AS S1 
    CROSS APPLY 
    TVF_AllWebParts_Site(S1.Id) AS AWPV 
    OUTER APPLY 
    TVF_AllDocVersions_SiteDocIdUIVersion(S1.Id, AWPV.tp_PageUrlID, AWPV.tp_PageVersion) AS ADV
    WHERE ADV.Id IS NULL AND AWPV.tp_IsCurrentVersion = 0 
    ) AS OrphanedWebParts 
    GO 
    

    Then use the below SQL script to clean up the orphan entries:

    USE WSS_Content; 
    
    GO 
    
    DECLARE @chunkSize INT; 
    
    SET @chunkSize = 1000; 
    
    -- Entries in the Personalization table are automatically cleaned up by _OnDeleteWebParts
    -- All we need to do is find any WebParts that exist that are not mapped to a DocVersion
    
    WHILE 1=1 
    
    BEGIN 
    DELETE TOP(@chunkSize) AWP FROM TVF_Sites_ALL() AS S 
    CROSS APPLY 
    TVF_AllWebParts_Site(S.Id) AS AWP 
    OUTER APPLY 
    TVF_AllDocs_Id_Level(S.Id,AWP.tp_PageUrlID, AWP.tp_Level) AS AD 
    WHERE AD.Id IS NULL AND AWP.tp_IsCurrentVersion = 1; 
    IF (@@ROWCOUNT = 0) 
    BREAK 
    END 
    
    WHILE 1=1 
    BEGIN 
    DELETE TOP(@chunkSize) AWPV FROM TVF_Sites_ALL() AS S1 
    CROSS APPLY 
    TVF_AllWebParts_Site(S1.Id) AS AWPV 
    OUTER APPLY 
    TVF_AllDocVersions_SiteDocIdUIVersion(S1.Id, AWPV.tp_PageUrlID, AWPV.tp_PageVersion) AS ADV
    WHERE ADV.Id IS NULL AND AWPV.tp_IsCurrentVersion = 0; 
    IF (@@ROWCOUNT = 0) 
    BREAK 
    END 
    
    WHILE 1=1 
    BEGIN 
    -- Remove any WebParts in WebPartLists cache that may have been deleted 
    DELETE TOP(@chunkSize) WPL FROM TVF_Sites_ALL() AS S1 
    CROSS APPLY 
    TVF_WebPartLists_Site(S1.Id) AS WPL 
    OUTER APPLY
    TVF_AllWebParts_SitePartId(S1.Id, WPL.tp_WebPartID) AS AWP 
    WHERE AWP.tp_ID IS NULL; 
    IF (@@ROWCOUNT = 0) 
    BREAK 
    END 
    
    GO 
    

    Note: you need to change WSS_Content to your content database of your web application which hosts the site. And Before you run the above, please back up your content database.

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, May 26, 2017 3:45 AM
    Moderator
  • Hi,

    I am checking to see how things are going there on this issue.

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, June 5, 2017 6:51 AM
    Moderator
  • Hello Wendy, I am trying to run the provided scripts because I have the same error. I am missing all of the TVF functions. Can you provide those as well. Thanks!

    Tuesday, December 5, 2017 8:29 AM