Add Field (Data Management)

Summary

Adds a new field to a table or the table of a feature class or feature layer, as well as to rasters with attribute tables.

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 Field Length parameter is only applicable to fields of type text. If a length is not specified, the length will default to 255.

  • For geodatabases, if field type defines a character or number, <null> is inserted into each record if the Field Is Nullable parameter is checked (field_is_nullable="NULLABLE" in Python).

  • A nonnullable field cannot be added to a nonempty geodatabase feature class or table.

  • A shapefile does not support aliases for fields, so you cannot add a field alias to a shapefile.

  • The Field Domain parameter can use an existing domain from a feature class in a geodatabase. The name of an existing domain must be provided. Providing an invalid domain name or value will not cause the tool to fail, but the invalid name or value will be ignored and no domain will be set for the field.

  • The precision and scale of a field describe the maximum precision and size of data that can be stored in the field. The precision describes the number of digits that can be stored in the field, and the scale describes the number of decimal places for float and double fields. For example, if the field value is 54.234, scale = 3 and precision = 5.

    Use the following guidelines for choosing the correct field type for a given precision and scale:

    • When you create a float, double, or integer field and specify 0 for precision and scale, the tool will attempt to create a binary type field if the underlying database supports it. File geodatabases support only binary type fields, and precision and scale are ignored.
    • When you create float and double fields and specify a precision and scale, if the precision is greater than 6, use a double; otherwise, use a float. If you create a double field and specify a precision of 6 or less, a float field will be created. If you create a float field and specify a precision greater than 6, a double field will be created.
    • If you specify a scale of 0 and a precision of 10 or less, create an integer field. When creating an integer field, specify a precision of 10 or less, or your field may be created as a double.
  • When creating a new field in a geodatabase feature class or table, you can specify the field's type but not its precision and scale. Even if the dialog box allows you to add a value for precision or scale, the value will be ignored during execution.

  • Required fields are permanent and cannot be deleted. To allow for deletion at a later time, set the field to nonrequired (the default).

  • 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.

Parameters

LabelExplanationData Type
Input Table

The input table to which the specified field will be added. The field 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.

Mosaic Layer; Raster Layer; Table View
Field Name

The name of the field that will be added to the input table.

String
Field Type

Specifies the field type of the new field.

  • TextAny string of characters.
  • Float (single precision) Fractional numbers between -3.4E38 and 1.2E38.
  • Double (double precision) Fractional numbers between -2.2E308 and 1.8E308.
  • Short (small integer) Whole numbers between -32,768 and 32,767.
  • Long (large integer) Whole numbers between -2,147,483,648 and 2,147,483,647.
  • DateDate and/or time.
  • Blob (binary data)Long sequence of binary numbers. You need a custom loader or viewer or a third-party application to load items into a BLOB field or view the contents of a BLOB field.
  • Raster imageryRaster images. All ArcGIS software-supported raster dataset formats can be stored, but it is highly recommended that only small images be used.
  • GUID (globally unique identifier)Globally unique identifier.
String
Field Precision
(Optional)

The number of digits that can be stored in the field. All digits are counted regardless of which side of the decimal they are on.

If the input table is a file geodatabase, the field precision value will be ignored.

Long
Field Scale
(Optional)

The number of decimal places stored in a field. This parameter is only used in float and double data field types.

If the input table is a file geodatabase, the field scale value will be ignored.

Long
Field Length
(Optional)

The length of the field being added. This sets the maximum number of allowable characters for each record of the field. This parameter is only applicable to fields of type text.

Long
Field Alias
(Optional)

The alternate name given to the field name. This name is used to describe cryptic field names. This parameter only applies to geodatabases.

String
Field IsNullable
(Optional)

Specifies whether the field can contain null values. Null values are different from zero or empty fields and are only supported for fields in a geodatabase.

  • Checked—The field will allow null values. This is the default.
  • Unchecked—The field will not allow null values.
Boolean
Field IsRequired
(Optional)

Specifies whether the field being created is a required field for the table. Required fields are only supported in a geodatabase.

  • Checked—The field is a required field. Required fields are permanent and cannot be deleted.
  • Unchecked—The field is not a required field. This is the default.
Boolean
Field Domain
(Optional)

Constrains the values allowed in any particular attribute for a table, feature class, or subtype in a geodatabase. You must specify the name of an existing domain for it to be applied to the field.

String

Derived Output

LabelExplanationData Type
Updated Input Table

The updated input table.

Table

arcpy.management.AddField(in_table, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})
NameExplanationData Type
in_table

The input table to which the specified field will be added. The field 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.

Mosaic Layer; Raster Layer; Table View
field_name

The name of the field that will be added to the input table.

String
field_type

Specifies the field type of the new field.

  • TEXTAny string of characters.
  • FLOAT Fractional numbers between -3.4E38 and 1.2E38.
  • DOUBLE Fractional numbers between -2.2E308 and 1.8E308.
  • SHORT Whole numbers between -32,768 and 32,767.
  • LONG Whole numbers between -2,147,483,648 and 2,147,483,647.
  • DATEDate and/or time.
  • BLOBLong sequence of binary numbers. You need a custom loader or viewer or a third-party application to load items into a BLOB field or view the contents of a BLOB field.
  • RASTERRaster images. All ArcGIS software-supported raster dataset formats can be stored, but it is highly recommended that only small images be used.
  • GUIDGlobally unique identifier.

Although the Field object's type property values are not an exact match for the keywords used by the Add Field tool's field_type parameter, all of the Field object's type values can be used as input to this parameter. The different field types are mapped as follows: Integer to LONG, String to TEXT, and SmallInteger to SHORT.

String
field_precision
(Optional)

The number of digits that can be stored in the field. All digits are counted regardless of which side of the decimal they are on.

If the input table is a file geodatabase, the field precision value will be ignored.

Long
field_scale
(Optional)

The number of decimal places stored in a field. This parameter is only used in float and double data field types.

If the input table is a file geodatabase, the field scale value will be ignored.

Long
field_length
(Optional)

The length of the field being added. This sets the maximum number of allowable characters for each record of the field. This parameter is only applicable to fields of type text.

Long
field_alias
(Optional)

The alternate name given to the field name. This name is used to describe cryptic field names. This parameter only applies to geodatabases.

String
field_is_nullable
(Optional)

Specifies whether the field can contain null values. Null values are different from zero or empty fields and are only supported for fields in a geodatabase.

  • NON_NULLABLEThe field will not allow null values.
  • NULLABLEThe field will allow null values. This is the default.
Boolean
field_is_required
(Optional)

Specifies whether the field being created is a required field for the table. Required fields are only supported in a geodatabase.

  • NON_REQUIREDThe field is not a required field. This is the default.
  • REQUIREDThe field is a required field. Required fields are permanent and cannot be deleted.
Boolean
field_domain
(Optional)

Constrains the values allowed in any particular attribute for a table, feature class, or subtype in a geodatabase. You must specify the name of an existing domain for it to be applied to the field.

String

Derived Output

NameExplanationData Type
out_table

The updated input table.

Table

Code sample

AddField example 1 (Python window)

The following Python window script demonstrates how to use the AddField function in immediate mode.

import arcpy
arcpy.env.workspace = "C:/data/airport.gdb"
arcpy.AddField_management("schools", "ref_ID", "LONG", 9, "", "", "refcode", 
                          "NULLABLE", "REQUIRED")
AddField example 2 (stand-alone script)

The following stand-alone script demonstrates how to use the AddField function.

# Name: AddField_Example2.py
# Description: Add a pair of new fields to a table
 
# Import system modules
import arcpy
 
# Set environment settings
arcpy.env.workspace = "C:/data/airport.gdb"
 
# Set local variables
inFeatures = "schools"
fieldName1 = "ref_ID"
fieldPrecision = 9
fieldAlias = "refcode"
fieldName2 = "status"
fieldLength = 10

# Execute AddField twice for two new fields
arcpy.AddField_management(inFeatures, fieldName1, "LONG", fieldPrecision,
                          field_alias=fieldAlias, field_is_nullable="NULLABLE")

arcpy.AddField_management(inFeatures, fieldName2, "TEXT", 
                          field_length=fieldLength)

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics