I am trying to write a script that that changes the aliases of a table's fields, but when I ran it I got this code error:
ExecuteError: ERROR 001601: Failed to alter field alias.
Failed to execute (AlterField).
This makes no sense to me and I would love any input as to why this happened.
Also, here is my code that generated this error:
# Import geoprocessing import arcpy # Set workspace arcpy.env.workspace = r'U:\newberry\new.gdb' # Creates a list of fields from the Metadata_2010 table fieldListTable = arcpy.ListFields("METADATA_2010") # Creates a cursor - a data access object rows = arcpy.SearchCursor("METADATA_2010") # Creates an empty table to store row values fullNames = [] # For loop thats iterates through the rows in # the Full_Name field of the Metadata_2010 table for row in rows: # Adds the row value to the fullNames list fullNames.append(row.getValue(fieldListTable[2].name)) # Creates a sliced list of fields from the census block group # polygon feature class fieldList = arcpy.ListFields("please")[2:630] # For loop thats changes the existing alias name in the table # to the name in the fullNames list for i in range(len(fieldList)): arcpy.AlterField_management('please', str(fieldList.name),'',str(fullNames))
I did not use the descriptions from the metadata as field names, I used them as aliases. I'm guessing that replacing field names have some limitations on the length, where alias don't .
I've attached a picture of what a portion of my table looks like.
Thanks. I may use this myself. I did write a script to delete the 'Margin of Error' fields. Not relevant for our uses, and they double the number of fields. My data wasn't joined to the polygon file, though, when I downloaded it. Relationship classes are there, but not actually working.