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")
print(arcpy.Exists("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")
print(arcpy.Exists("Some_F_Layer"))
print(arcpy.Exists("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")