Hi, I'm attempting to use append to add data from one table to another, but I am getting the below error (I am writing this in a script, but have tested the append tool in ArcMap as well with the same error):
Traceback (most recent call last):
File "C:\Users\zieglerhm\Documents\ArcGIS\Projects\CW2020_IRP_DataProcessing\Script\WorkSummaryDataImport_v0.2.py", line 184, in <module>
arcpy.management.Append(gm_reh_sum_mem, gm_reh_sum_target, "NO_TEST", gm_reh_sum_fldmap, "Mechanical Cleaning/Root Removal")
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 3995, in Append
raise e
ExecuteError: ERROR 001156: Failed on input OID 1, could not write value '' to output field REHABLENGTH
Failed to execute (Append).
The problem is that the field in the source table is of type string while the field being mapped to in the target table is of type double. I was under the impression that field mapping would automatically convert to the new field data type, and the following discussion seems to be using this principle: arcpy - Change Field Type using Field Mapping for List of Tables using Python - Geographic Informati...
Has anyone encountered this error before, and if so, how did you solve it? Should field mapping change to the data type of the output field automatically?
Thank you for any help!
Solved! Go to Solution.
Hmmm... this page seems to say it's not possible: 001156: Failed on input OID ; could not write value '' to output field .—Help | ArcGIS Desktop
A value could not be added to the output field; for example, text values cannot be added to numeric fields, and text values cannot be added to text fields if the values are longer than the field length.
There are a number of links on this error message... you will probably have to sift through them here
Hmmm... this page seems to say it's not possible: 001156: Failed on input OID ; could not write value '' to output field .—Help | ArcGIS Desktop
A value could not be added to the output field; for example, text values cannot be added to numeric fields, and text values cannot be added to text fields if the values are longer than the field length.
So, the workaround is to copy it to a numeric value before appending, and update your remap table.
arcpy.AddField_management(gm_reh_sum_mem, "REHABLENGTHF", "DOUBLE")
arcpy.CalculateField_management(gm_reh_sum_mem, REHABLENGTHF,
"float(!REHABLENGTH!)", "PYTHON_9.3")
Hmm, that's the only solution I have found as well, I was hoping there was a more elegant way of doing it. I actually can't believe that there isn't, esri should make it easier to change column attribute types when field mapping. I know that the table to table tool allows you to change the field type being copied out to, but I can't figure out how to accomplish that when using the table to table tool in python. Anyway, thank you guys for the help!