1

Once in a while I encounter a field in my featureclasses that have their isNullable property set to No.

Is there a simple way using python to correct this?

I came up with this code, but unfortunately it's not doing anything.

print "Modify the RESERVE_ID field to allow NULLS"
desc = arcpy.Describe("OGMA_Final")
fields = desc.fields
for field in fields:
   print str(field.name)
   if field.name == "RESERVE_ID":
      print "Setting property for field"
      field.isNullable = True
print "Finished"
3

You're attempting to set the isNullable property on the wrong type of object, a Describe object. You need to get the field object of the featureclass, then you can get/set isNullable:

>>> import arcpy
>>> fields = arcpy.ListFields("WGS84Points")
>>> for field in fields:
...     print field.isNullable
...     
False
False
False
False
False
False
>>> for field in fields:
...     field.isNullable = True
...     
>>> for field in fields:
...     print field.isNullable
...     
True
True
True
True
True
True
>>> 
  • Hi Chad, thanks for responding. I tried your suggestion, and also printed to screen the property as you did and that all looked good. True all the way down in the py shell. But when I opened up the data to view the field properties in ArcCatalog, the troublesome field still says Allow NULL values No. How strange. Any ideas what might cause this? – User Error Jul 11 '13 at 18:53
  • @UserError - so you got this to work? I looked at it some earlier, but got nowhere. – Chad Cooper Jul 12 '13 at 20:25
  • I didn't get it to work. I was getting the same output as you were, but when I go to ArcCatalog the property has not changed. I didn't have much time to play with it so I added a new field, calculated the values over and dropped the problem one. Next time I encounter this I will explore your method some more. Thanks again. – User Error Jul 15 '13 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.