Skip to content

Instantly share code, notes, and snippets.

@jannefleischer
Forked from steveoh/fouled_up_column.py
Created January 17, 2019 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jannefleischer/07b94c52b5d33f829ba7633fcd2c41d8 to your computer and use it in GitHub Desktop.
Save jannefleischer/07b94c52b5d33f829ba7633fcd2c41d8 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment