Select to view content in your preferred language

Preserve GlobalIDs with python truncate append

668
2
Jump to solution
07-21-2023 07:59 AM
kapalczynski
Occasional Contributor III

I have a script that I am trying to truncate and append features from one DB to another... DEV to TEST

The truncate and Append works but I need to preserve the GlobalIDs.   

I read that this is what I need to define but the GlobalIDs on the out FC are different than the original ... Again these are in different DBs but same FC name

Note this is an Enterprise Geodatabase....

Any thoughts?

 

# Set the preserveGlobalIds environment to True
arcpy.env.preserveGlobalIds = True

 

 

# --Import arcpy module--------------------------------------------------------------------------------------
import arcpy

layers_to_Modify = {
"Database Connections\\GIS_DEV@gis_data.sde\\GIS_DATA.AAAA": "Database Connections\\GIS_TEST@gis_data.sde\\GIS_DATA.AAAA"
}

# Set the preserveGlobalIds environment to True
arcpy.env.preserveGlobalIds = True

def truncateAppendData():
    print("Starting to Replace the data")
    for layer in layers_to_Modify.keys():
        fromRelationship = layer
        toRelationship = layers_to_Modify[layer]      
        try:      
            arcpy.TruncateTable_management(toRelationship)
            arcpy.Append_management(fromRelationship, toRelationship, "NO_TEST")
            print("-- append Successful...".format())
        except Exception:
            # Handle errors accordingly...this is generic
            tb = sys.exc_info()[2]
            tb_info = traceback.format_tb(tb)[0]
            # Python 3.x
            #pymsg = f'PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n'
            #msgs = f'ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n'
            # Python 2.7
            pymsg = 'PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n'
            msgs = 'ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n'
            print(pymsg)
            print(msgs)
            print.error("-- PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n".format())
            print.error("-- ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n".format())

if __name__ == '__main__':

    ## Truncate and Append Data
    truncateAppendData()

 

 

 

 

 

1 Solution

Accepted Solutions
kapalczynski
Occasional Contributor III

Please REFER to the original post... that code works ....

 

View solution in original post

0 Kudos
2 Replies
kapalczynski
Occasional Contributor III

UGGGGGGG my mistake... I was looking at the wrong Feature Class in the Destination... duh.... That code is working fine.... 

Cheers

0 Kudos
kapalczynski
Occasional Contributor III

Please REFER to the original post... that code works ....

 

0 Kudos