How to delete a GlobalID-based relationship class

796
4
10-31-2017 08:44 AM
AngelaDeegan1
New Contributor II

I have two feature classes (wControlValve and wBlowOff) that I need to drop and recreate weekly (part of a migration of data from Smallworld to ESRI). Once they're recreated, I create an ObjectID-based relationship class which I then migrate to a GlobalID-based relationship class. I successfully created it once. The problem is I can't delete it in order to recreate it every week!  I've tried right-clicking it and choosing "Delete" which always appears to be successful - at first - but then when I refresh, the relationship class is still there.  I also haven't been able to delete it via python (which is actually how I need to accomplish it). I've tried when everyone is off but me (as sde - see attachment), but still get the lock message. Any ideas?

>>> arcpy.env.workspace = "Database Connections/aoprod-sde.sde"

>>> arcpy.Exists('gis.sde.wControlValve_wBlowOff')

True

>>> arcpy.Delete_management('gis.sde.wControlValve_wBlowOff')

Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py", line 4341, in Delete raise e ExecuteError: ERROR 000601: Cannot delete Database Connections/aoprod-sde.sde\gis.sde.wControlValve_wBlowOff. May be locked by another application. Failed to execute (Delete).

>>>

0 Kudos
4 Replies
JoeBorgione
MVP Emeritus

Would something like this work for you?

https://community.esri.com/thread/185718-delete-relationship-class 

That should just about do it....
0 Kudos
AngelaDeegan1
New Contributor II

Thanks for the suggestion. It was worth a shot. But I still got the same result.

>>> arcpy.env.workspace = "Database Connections/aoprod-sde.sde"

>>> arcpy.Delete_management('gis.sde.wControlValve_wBlowOff', "RelationshipClass")

Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py", line 4341, in Delete raise e ExecuteError: ERROR 000601: Cannot delete Database Connections/aoprod-sde.sde\gis.sde.wControlValve_wBlowOff. May be locked by another application. Failed to execute (Delete).

0 Kudos
JoeBorgione
MVP Emeritus

Hey Angela- just for future reference, you can post python scripts just the way you see it in idle or the python window if you click on the three dots (Expand ToolBar), and the expand More, choose Syntax Highlighter, and finally in the window select Python.  That way.....

>>> arcpy.env.workspace = "Database Connections/aoprod-sde.sde"

>>> arcpy.Delete_management('gis.sde.wControlValve_wBlowOff', "RelationshipClass")

looks like 

>>> arcpy.env.workspace = "Database Connections/aoprod-sde.sde"
>>> arcpy.Delete_management('gis.sde.wControlValve_wBlowOff', "RelationshipClass")

 which is a whole lot easier for most to read.

same goes for python code:  

import os
import arcpy

#arcpy.env.workspace = r"C:\Users\arcgis\Desktop\Python"
#arcpy.env.workspace = r"D:\Datasets\Forestry\ORM\WIN-E5O1QRU6EGO.sde\FORESTRY.ARCGIS.ORM\FORESTRY.ARCGIS.Settings"

selecting_features = arcpy.GetParameterAsText(0)
gross = "GACRES"
expression = "float(!SHAPE.area!) * 10.7639/43560"

#You need edit session, if it's versioned
print("Starting session")

arcpy.AddMessage("Starting session")

#Create update cursor for feature class in attribute table

print("Updating attribute...")

arcpy.AddMessage("Updating attribute...")


arcpy.CalculateField_management(selecting_features, gross, expression, "PYTHON_9.3")

is better when it's:

import os
import arcpy

#arcpy.env.workspace = r"C:\Users\arcgis\Desktop\Python"
#arcpy.env.workspace = r"D:\Datasets\Forestry\ORM\WIN-E5O1QRU6EGO.sde\FORESTRY.ARCGIS.ORM\FORESTRY.ARCGIS.Settings"

selecting_features = arcpy.GetParameterAsText(0)
gross = "GACRES"
expression = "float(!SHAPE.area!) * 10.7639/43560"

#You need edit session, if it's versioned
print("Starting session")

arcpy.AddMessage("Starting session")

#Create update cursor for feature class in attribute table

print("Updating attribute...")

arcpy.AddMessage("Updating attribute...")


arcpy.CalculateField_management(selecting_features, gross, expression, "PYTHON_9.3")
That should just about do it....
0 Kudos
AngelaDeegan1
New Contributor II

Okay thanks for the tip.

0 Kudos