Summary
Adds new fields to a table, feature class, or raster.
Usage
For shapefiles and dBase tables, if field type defines a character, blanks are inserted for each record. If field type defines a numeric item, zeros are inserted for each record.
The Add Fields tool has the following default field properties:
- Added fields Allow NULL property will be true.
- Added fields Editable property will be true.
- Added fields Required property will be false.
- Precision and scale are set by the field type and data source defaults.
The field length is only applicable to fields of type text.
A shapefile does not support aliases for fields, so you cannot add a field alias to a shapefile.
A field of type raster allows you to include a raster image as an attribute. It is stored in or alongside the geodatabase. This is helpful when an image is the best way to describe a feature. Precision, scale, and length cannot be set for fields of type raster.
Syntax
arcpy.management.AddFields(in_table, field_description)
Parameter | Explanation | Data Type |
in_table | The input table where the fields will be added. The fields will be added to the existing input table and will not create a new output table. Fields can be added to feature classes in geodatabases, shapefiles, coverages, stand-alone tables, raster catalogs, rasters with attribute tables, and layers. | Table View; Raster Layer; Mosaic Layer |
field_description [[Field Name, Field Type, {Field Alias}, {Field Length}, {Default Value} {Field Domain}],...] | The fields and their properties that will be added to the input table.
Available field types are as follows:
In the field_description parameter with optional parameters, use None as an empty place holder. | Value Table |
Derived Output
Name | Explanation | Data Type |
out_table | The updated input tables. | Table View; Raster Layer; Mosaic Layer |
Code sample
The following Python window script demonstrates how to use the AddFields tool in immediate mode.
import arcpy
arcpy.env.workspace = "C:/data/district.gdb"
arcpy.management.AddFields(
'school',
[['school_name', 'TEXT', 'Name', 255, 'Hello world', ''],
['street_number', 'LONG', 'Street Number', None, 35, 'StreetNumDomain'],
['year_start', 'DATE', 'Year Start', None, '2017-08-09 16:05:07', '']])
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes