3

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)?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 25, 2014 at 19:35
5
  • 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). Commented Apr 25, 2014 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. Commented Apr 25, 2014 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. Commented Apr 25, 2014 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? Commented Apr 26, 2014 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! Commented Apr 26, 2014 at 16:55

2 Answers 2

3

The Documentation for 10.3 shows that you can remove domains by using an empty string and a setting the clear_value parameter to true. This worked for me in ArcGIS 10.4.1, but I don't know if it works in anything before 10.3

arcpy.AssignDefaultToField_management(FC, field.name, "", "", "TRUE")

As you can see I had to pass in an empty string value for subtype as well, even though the feature may not have a subtype

answered Apr 13, 2018 at 19:52
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"
answered May 8, 2014 at 17:46
2
  • 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. Commented May 12, 2014 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 Commented May 13, 2014 at 6:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.