I would like to append the data from one feature class to another after confirming that the schemas match in both feature classes.
I can append the data from one FC to another by using this simple code:
arcpy.DeleteFeatures_management(outFeatureClass) arcpy.Append_management("FC", outFeatureClass, "TEST", "")
...but what I would like to do is stop execution of this code completely if the schemas have changed...in my example above, the data has already been deleted by the time that the schema change parameter ("TEST) fails. I am using 'Append...' b/c these feature classes are connected to map services.
Ideally, I would like to first compare the schemas, and then continue to delete/append if they match. If they do not, I would like to send an email, and end the script.
I have tried using the FeatureCompare tool, which will print a message if the schemas do not match, but I haven't figured out if or how I can use the data in this message as a variable in my code:
compare_result = arcpy.FeatureCompare_management(inFC, outFC, "OBJECTID", "SCHEMA_ONLY", "","","","","","","CONTINUE_COMPARE") print arcpy.GetMessages()
When I run this code, one line of the output message reads:
Table: Tables have different number of fields (Base: 48, Test: 47).
...if there has been a change, or
Field: Field properties are the same.
...if the schemas match.
Is there a way I can somehow use this information to set a flag or boolean in my code?
I also considered using a SearchCursor, but I am not so sure that is the right idea.
I am currently able to send an email confirming that the script was successful or if there was an error, but I would prefer to send an email before an error has already resulted in a faulty map service.