0

I am trying to import CSV data into an existing geodatabase in ArcMap. I want to import to the existing geodatabase fields to ensure my CSV data satisfies whatever rules are set up in the geodatabase.

This is my Python script:

import arcpy
from arcpy import env
env.workspace = "C:/GISJobs/workspace"
arcpy.TableToTable_conversion("Trapping.csv", "C:/GISJobs/workspace/GDB_BLANK.gdb", "Trapping")

But I get this error:

Runtime error Traceback (most recent call last): File "", line 5, in File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\conversion.py", line 2276, in TableToTable raise e ExecuteError: ERROR 000258: Output C:/GISJobs/workspace/PWIS_GDB_BLANK_181106.gdb\Trapping already exists Failed to execute (TableToTable).

I don't have the geodatabase open anywhere. The script works perfectly to create a new table, but not to write into an existing table. Any ideas?

1
  • 2
    Are you trying to append data to an existing table? It is telling you that the table already exists in your database
    – BERA
    May 4, 2021 at 9:20

1 Answer 1

1

You cannot append new data into existing by just copy/paste or conversions. It will try to replace you existing table. If you have updated your table previously and you want to replace you existing table, all you have to do is to insert this line after importing arcpy.

arcpy.env.overwriteOutput = True

However you should take a look to append tool. Pay attention to field mappings, if the schema are different you need to relate fields with each-other. If you have the same schema, just choose the schema type "TEST".

https://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/append.htm

3
  • Thank you, Append looks like the tool that I want. However in the linked example it appends a shapefile to a shapefile. I want to append CSV data to a feature class within a GDB. I am getting this error: "ERROR 000338: Inputs must be either all Feature Classes, Tables or Rasters; not mixed." If I convert my CSV to a feature class, it truncates all the field headings so they no longer match to the GDB feature class. Is there a workaround for this?
    – Mr Magoo
    May 5, 2021 at 5:29
  • The feature class should be the same same, so if you are trying to append some information to a point featrure class, you have to convert you data into point feature class than append to existing. For your case you should convert your CSV into a feature class and append to your target layer. If you save the featureclass inside a geodatabase the fields name will not be truncated.
    – riflo
    May 5, 2021 at 8:32
  • 1
    Thanks for your help. I have successfully appended the data! For anyone else out there, this was my solution to append CSV data to an existing geodatabase feature class: - Add the CSV dataset as a layer to ArcMap using 'Add XY data' - Export the layer to a new feature class within my target geodatabase - Append the new feature class data to my target feature class using the Append python script, example here: desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/… - Deleted the new feature class from the geodatabase
    – Mr Magoo
    May 5, 2021 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.