Hello!
I need to add unique ID's to a specific field in multiple feature classes that are inside a geodatabase.
I have created the code below but it is not working.
When I run, it I get the following error message:
Traceback (most recent call last):
File "D:/APRX_MXDS/USA_Parcels_2019_Project/Scripts/UniqueID_2.py", line 15, in <module>
for row in cursor:
RuntimeError: A column was specified that does not exist.
Process finished with exit code 1
The error is referring to a column that does not exist.
Is column the same as field?
The field "UNIQUE_ID_PYTHON" was created before running the code, and so it should run.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> uuid
<SPAN class="comment token"># Script to add unique Id's</SPAN>
featureGDB <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"D:\APRX_MXDS\USA_Parcels_2019_Project\test_featureclasses.gdb"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> featureGDB
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
List_fc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*single"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># get a list of feature classes that end with the word single.</SPAN>
List <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"UNIQUE_ID_PYTHON"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># Field where I want to add the unique ids </SPAN>
<SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> List_fc<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># loop through each feature class in the list and add unique ID to the specified field.</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> List<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">'{'</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>uuid<SPAN class="punctuation token">.</SPAN>uuid4<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'}'</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Not sure how to fix this.
Can somebody guide me ?
Thank you