Select to view content in your preferred language

Error to join multiple table

257
1
03-14-2023 10:22 PM
Labels (1)
ashwaniparashar
New Contributor

import arcpy

# Set the workspace
arcpy.env.workspace = r"X:\Layerstack"

# Set the input and join tables
target_table = "Layer_1_tab.dbf"
join_tables = ["Layer_1_tab.dbf", "Layer_2_tab.dbf", "Layer_3_tab.dbf"]

# Set the fields to join on
target_field = "key"
join_field = "key"

# Join the tables to the target table using a loop
for table in join_tables:
join_field_table = arcpy.ListFields(table, join_field)
join_field_table_type = join_field_table[0].type
join_field_target = arcpy.ListFields(target_table, target_field)[0].type
if join_field_table_type != join_field_target:
arcpy.AlterField_management(table, join_field, target_field, target_field)
arcpy.JoinField_management(target_table, target_field, table, target_field)
Traceback (most recent call last):
File "<string>", line 21, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 9027, in JoinField
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 9024, in JoinField
retval = convertArcObjectToPythonObject(gp.JoinField_management(*gp_fixargs((in_data, in_field, join_table, join_field, fields, fm_option, field_mapping), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 001706: Cannot join a table to itself.
Failed to execute (JoinField).

0 Kudos
1 Reply
DanPatterson
MVP Esteemed Contributor

line numbers would help

Code formatting ... the Community Version - Esri Community

The error is explicit

ERROR 001706: Cannot join a table to itself.

Throw in some print statements to see what tables you are trying to join together


... sort of retired...
0 Kudos