arcpy.da.instercursor adding blank rows.

790
3
09-07-2018 09:05 AM
Lim_Shane
New Contributor II

I am trying to copy a table from an oracle server to a filegdb table.  I can get the searchcursor to work and I can get the insercursor to add all the rows but the field values are all blank.  Any ideas?

arcpy.CreateTable_management(targetPath,targetTableName,SourceTableFullPath,"#")

field_names = [f.name for f in arcpy.ListFields(SourceTableFullPath)] 


edit = arcpy.da.Editor(targetPath)

edit.startEditing(False,True)
edit.startOperation()
cursor = arcpy.da.InsertCursor(TargetTablefullPath,field_names)

i = 0
for row in arcpy.da.SearchCursor(SourceTableFullPath, field_names, sourceFilterString):
   i = i + 1

   print row[0] + " " + row[1]
   cursor.insertRow(row)
   if i > 10:
   print i
   break

print "added rows?"
edit.stopOperation()
edit.stopEditing(True)

del row
del cursor

0 Kudos
3 Replies
DarrenWiens2
MVP Honored Contributor

Since you're starting and immediately stopping an edit session, you may as well remove all that and see if it helps.

0 Kudos
Lim_Shane
New Contributor II

I didn't have any of that in to begin with.  I just started at creating the cursor but I still have the same problem.  I also tried doing it to a personal GDB.  All I can think of is that the new table gets an objectid field and somehow that is messing with the field count but even when I only call out two fields manually they still go in blank. 

0 Kudos
Lim_Shane
New Contributor II

I ended up creating a second copy of the table to insert into.  The first table is somehow read only. 


outTbl = str(arcpy.CreateTable_management(targetPath,targetTableName,SourceTableFullPath,"#").getOutput(0))

outTable2 = str(arcpy.TableToTable_conversion(outTbl,targetPath, targetTableName2 ).getOutput(0))