Skip to content

Instantly share code, notes, and snippets.

@steveoh
Last active October 19, 2022 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save steveoh/02a1896b5af4632ebed9 to your computer and use it in GitHub Desktop.
Save steveoh/02a1896b5af4632ebed9 to your computer and use it in GitHub Desktop.
RuntimeError: A column was specified that does not exist. How to find which field
#: the fields in the feature class
actual = set([str(x.name) for x in arcpy.ListFields(r'')])
#: the fields you are trying to use
expected = set([])
fouled_up = expected - actual
import arcpy
import os
test_location = 'c:\\temp'
gdb_name = 'inspecific_error'
gdb_path = os.path.join(test_location, gdb_name) + '.gdb'
table_name = 'tell_me_the_column_name'
table_path = os.path.join(gdb_path, table_name)
fouled_up_fields = ['test', 'this_one']
if not os.path.exists(test_location):
os.makedirs(test_location)
arcpy.CreateFileGDB_management(test_location, gdb_name, 'CURRENT')
arcpy.CreateTable_management(gdb_path, table_name)
arcpy.AddField_management(table_path, 'test', 'TEXT')
try:
with arcpy.da.SearchCursor(table_path, fouled_up_fields) as cursor:
for row in cursor:
continue
except RuntimeError as e:
print 'tell me which one is missing!!'
print e
print 'oh thanks, not useful'
#: the fields in the feature class
actual = set([str(x.name) for x in arcpy.ListFields(table_path)])
#: the fields you are trying to use
my_silly_input = set(fouled_up_fields)
missing = my_silly_input - actual
print 'the fouled up columns are {}'.format(missing)
@jannefleischer
Copy link

jannefleischer commented Jan 17, 2019

In case anyone is googleing its way here: I created a bunch of foul fields by doing a join with arcpy.AddJoin and then use arcpy.FeatureClassToFeatureClass to make the join permanent. That seemed to be the wrong way. I only could fix my foul fields by joining via arcpy.JoinField instead (better way, anyway...).

@steveoh: Thanks to pointing out that there is an issue with foul fields. I've gotten almost crazy over this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment