I have a script that deletes a feature class and then recreates it. I've noticed that in ArcGIS Pro 2.0, as soon as a feature class is deleted, if there are any map layers that have that feature class as a data source, if they are visible, a schema lock error occurs. If they are turned off, they are automatically removed from the map (rather than simply remaining in the map with a broken data source).
It seems to happen both if I delete a data source while running a script, or if I do it in the python window. For example, in an ArcGIS Pro project, using the Python window, try:
arcpy.Delete_management(any feature class that is represented by a corresponding layer in the TOC)
If the layer is visible, you will get:
ExecuteError: ERROR 000464: Cannot get exclusive schema lock. Either being edited or in use by another application.
Failed to execute (Delete).
If the layer is not visible, it is removed from the map. Is there a way to prevent this from happening? I would prefer an option to have a layer remain with a broken data source rather than be automatically removed.
.updateConnectionProperties()
with the last optional argument set to False. Its tedious to change this for every layer that references that feature class, then after deleting, to point all the layers back to the feature class.