[updated] In a script tool i use the CreateTable_management function to calculate some values as a result of an intersection of two polygon layers. The script uses a Parameter to specify path und name of the table (type is Table inside the script too parameter list). But unfornutately, if the user selects a folder and name to store the table, CreateTable_management adds two, some three fields automatically and sets them as NotNullable. So i can't ignore them with my insert cursor. This only happens with folders, not with geodatabases (i tried only geodatabase, though).

What can i do about this? Can i suppress the field creation?

import arcpy
import os
# ...
# p5 = arcpy.GetParameterAsText(4) e.g.:
p5 = "C:/temp/foo"
arcpy.env.overwriteOutput = True
# ...
outpath = os.path.dirname(p5)
outname =  os.path.basename(p5)
res = arcpy.CreateTable_management(out_path=outpath,
field_names = [f for f in arcpy.ListFields(p5)]
for fn in field_names:
    print fn.name, fn.isNullable

# in my script i'm creatin the fields i need here ...
arcpy.AddField_management(p5, "myField", "LONG")
# the insert cursor fails with info tables
ic = arcpy.da.InsertCursor(p5,["myField"])
for d in range(10):
del ic

print "Table data:"
field_names = [f for f in arcpy.ListFields(p5)]
for fn in field_names:
    print fn.name,
print ""
sc = arcpy.da.SearchCursor(p5, ["*"])
for r in sc:
    print r
  • What fields are created as "NotNullable"?
    – artwork21
    Commented Jan 18, 2017 at 16:55
  • With the code above i get three fields [u'Rowid', u'OBJECTID', u'FIELD1'], eg. last field says: f.isNullable >>> False, it seems to be an info table. If i force to create with .dbf extension it creates two fields [u'OID', u'Field1'], Again Field1 is not Nullable. But my problem is, i don't what any fields to be created automatically. Commented Jan 18, 2017 at 17:27
  • Please edit the question to contain this critical information. Neither INFO nor dBase support the concept of NULLs.
    – Vince
    Commented Jan 18, 2017 at 17:46
  • May be this is critical to you, but for me it's a hint. If i have a script tool and the user specifies a name for a table, how should the script deal with it? How to figure out, which kind of table with what constraints do i have? If i ignore automatically created fields in my insertcursor i got errors, for example with info tables, i got the unspecific "SystemError: error return without exception set". At least I am searching for a straighforward solution for a simple task. Commented Jan 19, 2017 at 7:53
  • I changed my example above to show the "failing code" with the insert cursor, where i try to ignore the automatically created fields. Using a dbase table, i got no error, using a geodatabase table i got one additional field, ObjectID, and no error, too. Commented Jan 19, 2017 at 8:11


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.