1

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).

enter image description here

4
  • 1
    You could always use the remove index tool? Alter the field name then add the index back?
    – Hornbydd
    Commented Jun 14, 2023 at 20:12
  • @Hornbydd please see edits, my original question is not exactly true.
    – Binx
    Commented Jun 14, 2023 at 22:55
  • 1
    Does your "Unable to update..." message get printed? If so, remove the try/except, and then edit your question to include what the full exception error is. Including try/except in code is a great way to avoid seeing the real error messages that you actually need to see in order to fix the problem. (By the way, your 'pass' command does nothing there.) Commented Jun 14, 2023 at 23:28
  • I wasn't at first seeing that printed, but I do now. Agreed, I should have removed the try/except to further troubleshoot. Please see updates for error message.
    – Binx
    Commented Jun 15, 2023 at 13:59

1 Answer 1

3

Having explored the issue I believe what you are seeing is nothing more than a visual indication. You would never be allowed to create a field named called *bob or bob* as they are invalid, a field name must start with a letter and then contain only letters or an underscore. This is discussed on this page.

So it is ArcGIS Pro visually adding a * to the end of the field name if the field is indexed or adding a * to the beginning if the field is a SUBTYPE. I'm guessing because your field FCSUBTYPE is participating in a more complex scenario, i.e. allowing subtypes, you cannot alter its name as that would be breaking any connecting logic.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.