can't delete site columns that aren't referenced

16,383

Solution 1

Your need to find and remove both the content types that use the site column and also any lists or libraries that use the site column you are trying to delete. Use PowerShell to get the site column object using something like this:

 $column = $web.Fields[“Column Display Name”]

Then find all the places where it is used, using something like this:

$column.ListsFieldUsedIn()

which spits out two GUIDs -- the WebID and ListID -- of every place that uses this content type.

Below is a PowerShell script that loops over all the list GUIDs returned from ListFieldUsedIn() and then finds the subweb and list matching that GUID and prints out list name and subweb URL for each usage :

$site = Get-SPSite "http://sharepoint"
$rootweb = $site.rootweb
$siteColumnToRemove = "Column Display Name”
$sc = $rootweb.Fields[$siteColumnToRemove]
if ($sc)
{
    write-host "  Found Site Column '" $sc.Title "' in gallery" -ForegroundColor Gray
    foreach( $listusage in $sc.ListsFieldUsedIn() )
    {
        $listID = $listusage.ListID            
        foreach ($subweb in $site.allwebs)
        {
            foreach ($list in $subweb.lists)
            {
                if ($list.ID -eq $listID)
                {                     
                     write-host "    Site Column '" $sc.Title "' used in list '" $list.Title "' in site '" $subweb.Url "'" -BackgroundColor Yellow -ForegroundColor Black
                }
            }
        }
    }
}

Solution 2

Happens to SharePoint 2010 too. Try looking at:

$field.AllowDeletion = $TRUE
$field.Update()

When I set that, seemed to work. Now I just can't replicate it, in order to prove my point. Typical.

Solution 3

I had this same problem and was able to delete using SharePoint Designer - not sure if anyone can validate this works for them.

Share:
16,383
Evan Nagle
Author by

Evan Nagle

I work with Olo solving problems for people who want to order food online. I'm also a Stack Overflow alumnus and Microsoft alumnus. I love Jesus, my family, programming, Texas, and craft beer. Find me on twitter and GitHub as @aggieben.

Updated on June 04, 2022

Comments

  • Evan Nagle
    Evan Nagle almost 2 years

    I just created a couple of site columns and content types that reference them through VS2010. I updated one of the fields and then tried to redeploy, but after retracting, deploy failed because the site columns previously created were still there. I tried to delete them manually from the UI, and got an alert box with this message:

    Site columns which are included in content types cannot be deleted. Remove all references to this site column prior to deleting it.

    I dug around in SharePoint Manager and didn't find any references, so I used powershell to enumerate all the content types and lists looking for references to my site columns and found nothing.

    I tried to delete using PowerShell like this:

    $web.Fields.Delete("StartTime")
    

    which resulted in this error:

    Exception calling "Delete" with "1" argument(s): "Site columns which are included in 
    content types or on lists cannot be deleted. Please remove all instances of this site 
    column prior to deleting it."
    At line:1 char:19
    + $web.Fields.Delete <<<< ("StartTime")
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException
    

    Finally, a simple inspection of the columns in PowerShell shows the following:

    Title                               Id                                                         CanBeDeleted ParentList                                                       Sealed ListsFieldUsedIn                   
    -----                               --                                                         ------------ ----------                                                       ------ ----------------                   
    Start Time OBE                      6fa0d85b-9af1-408b-835f-d4c66536...                                True                                                                   False {}                                 
    Time Tracker Tags                   92bc866b-0415-45f0-b431-d4df69c4...                                True                                                                   False {}                                 
    

    I'm experienced with MOSS 2007 and new to SP2010, but I've never seen this happen before. Anyone have any hints?

  • Geeky Guy
    Geeky Guy almost 11 years
    Didn't work for me. The column does exist on the site, but it doesn't show up in Sharepoint Designer.
  • Evan Nagle
    Evan Nagle about 9 years
    Just a note here for readers that come after: like I said in my answer, this problem is ancient history for me, but I'm marking this as the accepted answer because it gives the most robust way of diagnosing the problem. Good luck!
  • bresleveloper
    bresleveloper about 9 years
    unfortunately still stuck