I am attempting to join a feature layer to a table view in order to export a table of all non-joining features in the table view by selecting NULLS from the join field related to the feature layer. When I attempt using AddJoin to accomplish this I am met with the following error.

ERROR: 999999: Error executing function. The layer has an invalid primary key

I have used AddJoin to join these two datasets earlier in my script successfully, but that was joining the Table View to the Feature Layer, not the other way around. Please see below for more details and code.

I create the Table View and confirm it exists with this bit of code:

for file in gdb_files:
    print("EDes table available: {}".format(file))
    if 'GIS' in file:
        print("Creating Table View for EDes file")
        arcpy.MakeTableView_management(os.path.join(gdb_path, file), "EDES_TableView")

I create the Feature Layers and confirm they exists with this bit of code:

arcpy.MakeFeatureLayer_management(os.path.join(gdb_path, "Some_SDE_FC"), "Some_F_Layer")
arcpy.MakeFeatureLayer_management(os.path.join(gdb_path, "Some_SDE_FC_2"), "Some_F_Layer_2")


I am able to join a table view and feature layer successfully prior to the error message with this bit of code:

arcpy.env.workspace = gdb_path
arcpy.AddJoin_management("Some_F_Layer", "BBL", "EDES_TableView", "BBL", "KEEP_ALL")
arcpy.CopyFeatures_management("Some_F_Layer", "Match")

But when I attempt to rejoin the same Table View and Feature Layer, but in the opposite order, I get the above mentioned error. See code bit below:

arcpy.AddJoin_management("EDES_TableView", "BBL", "Some_F_Layer", "BBL", "KEEP_ALL")

The issue was that I was trying to join back onto the table that I had already joined on previously. I needed to use Delete_management to remove the table view from memory, re-instantiate it from the same source, and perform the join again with the reversed datasets.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.