I'm used to using open source, not ArcPy functionality.
I am using the arcpy.AlterField_management() function to change field names from upper to lower case. I first ran into what looks like a common view/cache issue when renaming field names. That problem was solved by renaming the field name twice. There is one field that appears to not be changing though. After digging further into it, I found the attribute has a *
which I found means that it is indexed.
Can I change a field name that is indexed?
Edits
I seem to have been mistaken. I do not believe this to be an index issue anymore. The attribute does not have an *
on the end of it's field name which would indicate that it's indexed (new_filed*
). Instead the *
is located before the field name and is only seen if a user "adds an additional field" (*new_field
). I can double click on the f_code
and change it's name, but I cannot double click on the *FCSUBTYPE
and change it's name. Only ObjectID
is required.
Edits 2
As suggested by son of a beach, the try/except block was avoiding the error message. I can confirm that the first two Field Names were passed through the script and broke at *FCSUBSTYE
.
fc = "source"
fieldList = arcpy.ListFields(fc)
for field in fieldList:
if not field.required:
arcpy.AddMessage(field.name)
name_original = field.name
name_new = str(field.name).lower()
arcpy.AlterField_management(fc, name_original, "random")
arcpy.AlterField_management(fc, "random", name_new)
f_code
FCSUBTYPE
Traceback (most recent call last):
File "C:\Users\user\Repo\Lowercase Fields\case_insensitivity.py", line 19, in <module>
arcpy.AlterField_management(fc, name_original, "random")
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 5429, in AlterField
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 5426, in AlterField
retval = convertArcObjectToPythonObject(gp.AlterField_management(*gp_fixargs((in_table, field, new_field_name, new_field_alias, field_type, field_length, field_is_nullable, clear_field_alias), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 001600: Failed to alter field name.
Failed to execute (AlterField).
Failed script Field Name Lower...
Failed to execute (FieldNameLower).