AnsweredAssumed Answered

The field is not nullable

Question asked by Tonyalmeida on Nov 15, 2018
Latest reply on Nov 19, 2018 by rvburton

I have a feature layer that i am trying to populate a field from another layer using a Dictionary/spatial join. I am getting "The field is not nullable" on line 38. Some feature are not within the polygonLayer = 'Soils", so i can see why it's not populating the Class_ID field but how do I by pass this "The field is not nullable" and keep going regardless if the point layer field is blank?

# Import arcpy module  
import arcpy
import sys
import traceback
# scratch spatial join feature 
sjpoints = "In_memory\SpJoin" 
# define the field list from the spatial join to transfer 
# you can add more field names such as: ["TARGET_FID", "Field", "AnoterField"] 
sourceFieldsList = ["TARGET_FID", "Class_ID"] 
# point feature that will be updated 
pointLayer = "Bld_Class" 
# polygon feature that will be used 
polygonLayer = "Soils" 
# define the field list to the original points 
updateFieldsList = ["OID@", "Class"] 
# Allow overwrite of join results 
arcpy.env.overwriteOutput = True 

#Run the Spatial Join tool, using the defaults for the join operation and join type 
arcpy.SpatialJoin_analysis(pointLayer, polygonLayer, sjpoints) 
# populate the dictionary from the polygon 
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints, sourceFieldsList)} 

with arcpy.da.UpdateCursor(pointLayer, updateFieldsList) as cursor:     
    for Row in cursor:     
        keyValue = Row[0]
        if keyValue in valueDict:
            print keyValue
            for n in range (1,len(sourceFieldsList)):       
                Row[n] = valueDict[keyValue][n-1]     

del valueDict