Issue when trying to update row using Update cursor

1830
6
04-04-2017 09:33 AM
NaomiAng
New Contributor II

Hi, I am relatively new to Python and Arcpy and I am getting the below error message when I try to update values in a row in a temporary layer which I have created from an Oracle Spatial table.  I believe that it could be related to the fact that you cannot have auto-incremented columns in Oracle tables, but any help would be greatly appreciated.

Traceback (most recent call last):
  File "\\xxxxxx.py", line 49, in <module>
    cursor.updateRow(row)
RuntimeError: The table does not have an auto-incrementing column.

Here is my code:

import arcpy

#Set environment workspace
arcpy.env.workspace = r"C:\Users\..."

in_table = "TABLE1"
temp_layer = "TABLE1_area"
out_layer= "TABLE1_area.lyr"
temp_wksp= r"\\..."
count = 0

#Generate a temporary table
arcpy.MakeFeatureLayer_management(in_table,temp_layer,workspace=temp_wksp)

#Add a new field to the temporary table
arcpy.AddField_management(temp_layer,"AREA_TEMP","DOUBLE")
arcpy.AddField_management(temp_layer,"UNIQUE_ID","LONG")

fields = ["SHAPE@AREA","AREA_TEMP","UNIQUE_ID"]

#Populate the SHAPE_AREA2 field in each row using a SearchCursor and print out the results.
with arcpy.da.UpdateCursor(temp_layer,fields) as cursor:
    for row in cursor:
        row[1]=row[0]
        row[2]=count
        count += 1
        print("SHAPE@AREA: {0} AREA_TEMP: {1} UNIQUE_ID: {2}".format(row[0],row[1],row[2]))
        cursor.updateRow(row)
        del row

del cursor

arcpy.env.workspace = temp_wksp

arcpy.SaveToLayerFile_management(temp_layer, out_layer)

0 Kudos
6 Replies
JoshuaBixby
MVP Esteemed Contributor

It helps to post more of the error message.  The code snippet you posted executes several geoprocessing tools, anyone which can generate a variety of errors.

0 Kudos
DanPatterson_Retired
MVP Emeritus

as well as your workspaces...many scripting errors are saving and/or working in sketchy workspaces

0 Kudos
NaomiAng
New Contributor II

Ok thanks, I have updated my question with the full error message if this helps...

0 Kudos
NeilAyres
MVP Alum

What is the nature of TABLE1? Does it have an ObjectID?

And, by creating a temporary feature layer and then saving this to a layer file is not going to work imho.

The data will only exist for the duration of the session.

0 Kudos
DanPatterson_Retired
MVP Emeritus

make a real table from your source... then try to see if the script error goes away

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I think your problems start here:

#Generate a temporary table
arcpy.MakeFeatureLayer_management(in_table,temp_layer,workspace=temp_wksp)‍‍‍‍

Make Feature Layer doesn't create a temporary table, it creates "a feature layer."  Looking up feature layer in Esri's GIS Dictionary:

1[data analysis] A layer that references a set of feature data. Feature data represents geographic entities as points, lines, and polygons.

The workspace parameter for Make Feature Layer is about validating field names, not a location to create a temporary table.

There are several tools you can use to create a copy of a feature class into a scratch or in-memory workspace:  Copy, Copy Features, Feature Class to Feature Class.

0 Kudos