Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to remove default values from all fields used by all feature classes in an SDE geodatabase. I do not see a geoprocess for removing the default value, only setting it. So I am trying to set it to "".

My approach is to use python to iterate through each feature dataset, then feature class, then field, and set the default value to "".

Here's what I have so far:

import arcpy
from arcpy import env

env.workspace = r"Database Connections\mysde.sde"

dsList = arcpy.ListDatasets("*", "Feature")
for dataset in dsList:
   fcList = arcpy.ListFeatureClasses("*","",dataset)
   for fc in fcList:          
      flds = arcpy.ListFields(fc,"*","String")
      for fld in flds:
         arcpy.AssignDefaultToField_management(fc, fld.name, "")

      flds = arcpy.ListFields(fc,"*","Double")
      for fld in flds:
         arcpy.AssignDefaultToField_management(fc, fld.name, None)

      flds = arcpy.ListFields(fc,"*","SmallInteger")
      for fld in flds:
         arcpy.AssignDefaultToField_management(fc, fld.name, None)

      flds = arcpy.ListFields(fc,"*","Integer")
      for fld in flds:
         arcpy.AssignDefaultToField_management(fc, fld.name, None)

      flds = arcpy.ListFields(fc,"*","Single")
      for fld in flds:
         arcpy.AssignDefaultToField_management(fc, fld.name, None)           

When I run the script I get an error 000735 which means a default value is required.

How do I get around this (if at all possible)?

Thanks!

share|improve this question
1  
Not a full answer or anything, but, some thoughts: don't know why you're calling fcList.sort() unless you just want them done in a specific order... it'll loop through all the FCs either way. More specifically though, you're not going to be able to assign a default value to some fields (Shape, OID, ShapeLength, ShapeArea, possibly any "BLOB" field types - not sure about blobs). So, you need to exclude those from your default assignment. Also, you're likely going to have an issue assigning an empty string to a numeric field type. If accepts null, consider assigning None (not in quotes). –  John Apr 25 at 19:44
    
Also, you may want to write something into your script that checks for feature classes in the database at the I guess you'd say root level (not inside a dataset) if that's applicable for your situation. –  John Apr 25 at 19:46
    
I've tested using None and it still throws the 000735 error. All of my feature classes are in feature datasets. To only run the tool on valid fields I have changed the code. See above. –  evv_gis Apr 25 at 19:58
    
@evv_gis I've come across this before, it's not truly a bug just an oversight. Your error is something like 'a value is expected' - you are right the tool is for setting and not clearing. In my case I was able to trow something together in VB (or VBA, all the same) is that an option for you? –  Michael Miles-Stimson Apr 26 at 2:47
    
At this point, anything is an option. I have the VBA extension authorized, so if you have something, I'd greatly appreciate it! –  evv_gis Apr 26 at 16:55

1 Answer 1

You can not set default value like "" or None, as arcpy.AssignDefaultToField_management does not consider those as value.

Below is your script with some change in default values

import arcpy
from arcpy import env

env.workspace = r"Database Connections\mysde.sde"
dsList = arcpy.ListDatasets("*", "Feature")
for dataset in dsList:
   fcList = arcpy.ListFeatureClasses("*","",dataset)
   for fc in fcList:
      flds = arcpy.ListFields(fc,"*","String")
      for fld in flds:
         arcpy.AssignDefaultToField_management(fc, fld.name, " ")

      flds = arcpy.ListFields(fc,"*","Double")
      for fld in flds:
        # to bypass "Shape_Length" field as it has type "Double" 
        if not fld.name.lower().startswith("shape"):
          arcpy.AssignDefaultToField_management(fc, fld.name, 0)

      flds = arcpy.ListFields(fc,"*","SmallInteger")
      for fld in flds:
         arcpy.AssignDefaultToField_management(fc, fld.name, 0)

      flds = arcpy.ListFields(fc,"*","Integer")
      for fld in flds:
         arcpy.AssignDefaultToField_management(fc, fld.name, 0)

      flds = arcpy.ListFields(fc,"*","Single")
      for fld in flds:
         arcpy.AssignDefaultToField_management(fc, fld.name, 0)
print "done"
share|improve this answer
    
Surya - I have two issues with this solution, 1. is when a field has a domain, and 2. is that I want null values for these fields. " " and 0 would have to be added to the domain as a valid entry, and are definitely non null values. I did get this task done, unfortunately, I had to do this all by hand. It wasn't as horrible as I originally had planned. –  evv_gis May 12 at 20:40
    
@ew_gis - Yes, that is right. But, if you do not want to add any value as default then perhaps arcpy.AssignDefaultToField_management is not a right tool for this scenario. I went through the tool's help doc. Please check link –  Surya May 13 at 6:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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