[GIS] Joining field works in ArcMap but not in ArcPy

arcmaparcpyattribute-joinserror-000840

I am trying to join a field of values found within a DBF to a multi-polyline shapefile. They share a common field name (filename) and the values found within each are identical. I was able to run Join Field without a hitch in ArcMap, but I'm receiving two errors when I try to run it in Python with identical parameters. Here's the block of code:

merge_features = r"C:/Users/kellyj/Desktop/Projects/CostAnalysis/merge_features"
import arcpy
from arcpy import env

arcpy.env.workspace = merge_features
arcpy.AddJoin_management("merged_lines.shp", "filename", "merged_table.dbf", "filename")

These are the errors I receive:

ExecuteError: Failed to execute. Parameters are not valid.
The value cannot be a feature class
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Raster Catalog Layer.
ERROR 000840: The value is not a Mosaic Layer.
WARNING 000970: The join field filename in the join table merged_lines is not indexed. To improve performance, we recommend that an index be created for the join field in the join table.

Any thoughts as to what's happening here?

Best Answer

The input for AddJoin_management needs to be a feature layer, not a shapefile or feature class.

You can get around this by making a feature layer, and then joining that layer to your table. (You'll still get the "not indexed" warning, but that shouldn't prevent the script from executing.)

arcpy.MakeFeatureLayer_management("merged_lines.shp", "tempLayer")
arcpy.AddJoin_management("tempLayer", "filename", "merged_table.dbf", "filename")
Related Question