I keep getting the message "Objects in this class cannot be updated outside of an edit session." Can anyone tell me what I'm doing wrong?
def CreateRelationshipClasses(self):
# Set workspace
env.workspace = "C:\Users\jsparfitt\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\uppco@neptune.sde"
try:
# Go through list of relationship classes defined in variables.py and create them in file gdb
for rc in relClassList:
WriteToReport("Building " + rc["relClassName"] + " relationship class ...")
if (rc["addCalcKeyFields"]):
# ESRI BUG: Need to add string field to hold globalid values for both feature class and table
# Relationship classes between globalid and guid fields fail in Python
WriteToReport("Adding " + rc["originPrimaryKey"] + " field to " + rc["originTable"] + " ...")
arcpy.AddField_management(rc["originTable"], rc["originPrimaryKey"], "TEXT", "", "", 50)
WriteToReport("Adding " + rc["originForeignKey"] + " field to " + rc["destinationTable"] + " ...")
arcpy.AddField_management(rc["destinationTable"], rc["originForeignKey"], "TEXT", "", "", 50)
WriteToReport("Calculating " + rc["originPrimaryKey"] + " field values ...")
# Start an edit session. Must provide the worksapce.
edit = arcpy.da.Editor(env.workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(False, True)
arcpy.CalculateField_management(rc["originTable"], rc["originPrimaryKey"],
"!" + rc["realPrimaryKey"] + "!", "PYTHON")
WriteToReport("Calculating " + rc["originForeignKey"] + " field values ...")
edit.CalculateField_management(rc["destinationTable"], rc["originForeignKey"],
"!" + rc["realForeignKey"] + "!", "PYTHON")
# Create relationship class
arcpy.CreateRelationshipClass_management(rc["originTable"],
rc["destinationTable"],
rc["relClassName"],
rc["relClassType"],
rc["forwardLabel"],
rc["backwardLabel"],
rc["msgDirection"],
rc["cardinality"],
rc["attributed"],
rc["originPrimaryKey"],
rc["originForeignKey"]
)
except Exception, e:
print e.message
(Curtis Price formatted code, see Posting Code blocks in the new GeoNet)