Hi there,
how can I delete a relationship class from a Feature Service?
Can someone help?
Thanks Marco
See below for feature layer, you can alter for a table using item.tables instead.
Run first above the ######## line to see the names of the relationships and identify the one you want to delete. Then add in the part below the ####### and add in the relationship name.
from arcgis import GIS
agol = GIS("home")
## get the feature service using the item id
item = agol.content.get("FS_ITEM_ID")
## get the Feature Layer and its ID
## you might need to replace 0 with the proper layer index if more than one layer
lyr = item.layers[0]
## print to see the relationship details, take note of the name you want to delete
print(lyr.properties.relationships)
################################################################################
## Then run the script adding in the RELATIONSHIP_NAME below
## for each relationship
for rel in lyr.properties.relationships:
## if it has the name we are interested in
if rel["name"] == "RELATIONSHIP_NAME":
print(rel["name"])
## get details of relationship
remove = dict(rel)
## and delete
lyr.manager.delete_from_definition({"relationships" : [remove]})