Last active
October 19, 2022 03:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#: 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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...