I am having trouble trying to add multiple fields to polygon feature classes into a file geodatabase.
Here is the python script I am working with.
import arcpy
arcpy.env.overwriteOutput = True
#set the environment settings
arcpy.env.workspace = "Z:\\folder\\folder\\Practice\\Practice.gdb"
#Set local variables
fc = arcpy.ListFeatureClasses("Polygon")
#Main Loop to add fields to all Polygon feature classes in file geodatabase
for fc in arcpy.ListFeatureClasses():
arcpy.AddField_management(fc, "sourceOFData", "TEXT", "", "", "75", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "Source Last Edit Date", "DATE", "", "", "75", "True", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "uploadAuthority", "TEXT", "", "", "75", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "effectiveDate", "DATE", "","", "75", "", "True", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "expirationDate", "DATE", "", "", "75", "", "True", "NON_REQUIRED", "")
if fc == "DaviePSAP":
arcpy.AddField_management(fc, "sourcePSAPUnqID", "TEXT", "", "", "254", "", "NULLABLE", "NON_REQUIRED", "")
elif fc in arcpy.ListFeatureClasses():
arcpy.AddField_management(fc, "sourceUnqID", "TEXT", "", "", "254","", "NULLABLE", "NON_REQUIRED", "")
elif fc in arcpy.ListFeatureClasses():
arcpy.AddField_management(fc, "county", "TEXT", "", "", "75", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "state", "TEXT", "", "", "2", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "country", "TEXT", "", "", "2", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "agencyID", "TEXT", "", "", "100", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "serviceURI", "TEXT", "", "", "254", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "serviceURN", "TEXT", "", "", "", "254", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "serviceNumber", "TEXT", "", "", "15", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "agencyVCardURI", "TEXT", "", "", "254", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "displayName", "TEXT", "", "", "60", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "comments", "TEXT", "", "", "100", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "gcLabel", "TEXT", "", "", "150", "", "NULLABLE", "NON_REQUIRED", "")
print "Fields have been added to all tables. Good Job!"
I am getting the following error:
Traceback (most recent call last):
File "C:/Users/Desktop/AddField5.py", line 17, in <module>
arcpy.AddField_management(fc, "Source Last Edit Date", "DATE", "", "", "75", "True", "NON_REQUIRED", "")
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\management.py", line 3435, in AddField
raise e
ExecuteError: ERROR 000622: Failed to execute (Add Field). Parameters are not valid.
ERROR 000800: The value is not a member of NULLABLE | NON_NULLABLE.
I believe the issue is related to the parameters that I have used for the "Date" fields I am attempting to create. The current syntax works fine for fields that are just "TEXT" types.
Example
import arcpy
arcpy.env.overwriteOutput = True
#set the environment settings
arcpy.env.workspace = "Z:\\folder\\folder\\Practice\\Practice.gdb"
#Set local variables
fc = arcpy.ListFeatureClasses("Polygon")
#Main Loop to add fields to all Polygon feature classes in file geodatabase
for fc in arcpy.ListFeatureClasses():
arcpy.AddField_management(fc, "sourceOFData", "TEXT", "", "", "75", "", "NULLABLE", "NON_REQUIRED", "")
#arcpy.AddField_management(fc, "Source Last Edit Date", "DATE", "", "", "75", "True", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "uploadAuthority", "TEXT", "", "", "75", "", "NULLABLE", "NON_REQUIRED", "")
#arcpy.AddField_management(fc, "effectiveDate", "DATE", "","", "75", "", "True", "NON_REQUIRED", "")
#arcpy.AddField_management(fc, "expirationDate", "DATE", "", "", "75", "", "True", "NON_REQUIRED", "")
if fc == "DaviePSAP":
arcpy.AddField_management(fc, "sourcePSAPUnqID", "TEXT", "", "", "254", "", "NULLABLE", "NON_REQUIRED", "")
elif fc in arcpy.ListFeatureClasses():
arcpy.AddField_management(fc, "sourceUnqID", "TEXT", "", "", "254","", "NULLABLE", "NON_REQUIRED", "")
elif fc in arcpy.ListFeatureClasses():
arcpy.AddField_management(fc, "county", "TEXT", "", "", "75", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "state", "TEXT", "", "", "2", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "country", "TEXT", "", "", "2", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "agencyID", "TEXT", "", "", "100", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "serviceURI", "TEXT", "", "", "254", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "serviceURN", "TEXT", "", "", "", "254", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "serviceNumber", "TEXT", "", "", "15", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "agencyVCardURI", "TEXT", "", "", "254", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "displayName", "TEXT", "", "", "60", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "comments", "TEXT", "", "", "100", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(fc, "gcLabel", "TEXT", "", "", "150", "", "NULLABLE", "NON_REQUIRED", "")
This code works this way but I really need the date field arguments to work in conjunction with the added text fields. Any suggestions?
FYI: Still a novice when it comes to Python scripting.