I am trying to create a new field in an Enterprise GDB ...
I use the below and for some reason it creates the field with DOUBLE, 38, 8
arcpy.management.AddField(toFeatureClass, "LOCALITY", "LONG", 20, "", "", "Locality", "NULLABLE", "NON_REQUIRED")
I have a feeling specifying a field length is tripping it up. This is what Pro spits out as a default Python command for adding a "Long" field, you should be able to tweak this:
arcpy.management.AddField( in_table=toFeatureClass, field_name="LOCALITY", field_type="LONG", field_precision=None, field_scale=None, field_length=None, field_alias="Locality", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="" )
As I needed 15 digits I had to create a DOULBE with 15 digits and 0 decimal places as LONG only holds 10 digits.
You must use Double.
arcpy.management.AddField( in_table=toFeatureClass, field_name="LOCALITY", field_type="DOUBLE", # Use DOUBLE for high-precision numbers field_precision=15, # Total number of digits field_scale=0, # No decimal places field_alias="Locality", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED" )
Thank you all for your comments... So if I need the field to carry 15 digits I have to make it a DOUBLE with PRECISION of 15 and no DECIMALS?
Hey @kapalczynski
It appears that the long will be created as a double if the precision is 11 or more from this documentation here:
https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/add-field.htm
For a field with a scale of 0, use a long or short integer field type. When creating a long integer field, specify a precision of 10 or less, or the field may be created as a double.
Cody
Long field type I believe doesn't have precision or scale like (double or float) so the 20 would be ignored. Can you try without that?
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.