arcpy.DeleteField_managementas it's not working correctly each time in my stand alone script. I keep getting the ERROR 002557: Cannot delete field (random field) from layer when using the keep fields option. It's not the same field each time, just a random field and only happens about half the times that I run the script. It works when put in the Python window in Pro. Any thoughts would be appreciated
Do you have Pro running with the layer when using your standalone script?
Perhaps follow the reboot suggestion in the error's help
002557: Cannot delete field <value> from <value>.—ArcGIS Pro | Documentation
No the layer is not in Pro when the script is running. I created a script tool and run it that way with a blank Pro map. It's not open in any other program, and isn't read only. It's weird that it works about half the times that I run it other times it fails on a random field that it can't delete. I use the keep fields option parameter since it was easier with so many fields. It will work if you copy and paste into the python window every time.
Is the data on a local drive, network share or in an enterprise geodatabase?
It's on a local drive, in a file geodatabase
does your script tool have the featureclass/layer as a parameter and you select the field to delete? or is it a parameter-less script? If it is the latter, try adding the required parameters and see if it succeeds.
I would expect it to work flawlessly if running from the python window within Pro since it is "aware" of its surrounds and a parameterless tool may not be.
Sorry for the late reply. Yes the script tool has the feature class as a parameter initially but once it gets to this step it has gone thru a couple other processes. The actual delete fields part is now a hard-coded feature class from these previous steps. It did the same error now in the python window, but after deleting all data and running again it worked. But still no luck as running as a script tool