There are several previous posts about this but I can't seem to figure this out.
I have a versioned feature class that I am trying to write a python script for that will remove all the data from the table using either TruncateTable or DeleteRows. I have tried to start an edit session prior to this function but I keep getting the "Cannot Update Outside of an Edit Session" error. Code below. Any ideas what I'm doing wrong?
Thanks,
Josh
import arcpy, os
sde = r"C:\Users\User\AppData\Roaming\Esri\ArcGISPro\Favorites\sdeConnection.sde\FeatureDataset"
fc = r"C:\Users\User\AppData\Roaming\Esri\ArcGISPro\Favorites\sdeConnection.sde\FeatureDataset\FeatureClass"
workspace = os.path.dirname(sde)
edit = arcpy.da.Editor(workspace)
edit.startEditing(False, True)
edit.startOperation()
arcpy.management.DeleteRows(fc)
edit.stopOperation()
edit.stopEditing(True)