error: 9999999 the field is not nullable

4153
6
Jump to solution
06-04-2014 09:22 AM
JuanSerratosa_López
New Contributor
Hello everyone,

I have this python stand alone script wich is runing fine until gets to this part.

if gp.Exists(lcp_name+".shp") == 0:         gp.CostPath_sa("samp_lyr", cd_name, bl_name, "cost_path", "BEST_SINGLE", "")          # Export the cost of the LCP         vat = gp.searchcursor("cost_path")         row_n = vat.next()         cost1_list = []         while row_n:             cost1_list.append(row_n.pathcost)             row_n = vat.next()         cost1 = sum(cost1_list)         del vat, row_n, cost1_list          # Turns the raster LCP to a polyline         gp.RasterToPolyline_conversion("cost_path","temp.shp", "ZERO", "", "SIMPLIFY")         gp.Dissolve_management("temp.shp", lcp_name+".shp")         gp.delete_management("temp.shp")         gp.delete_management("cost_path")          # Calculate the length of the LCP.         gp.Addfield_management(lcp_name+".shp", "LENGTH", "DOUBLE")         gp.CalculateField_management(lcp_name+".shp", "LENGTH", "float(!SHAPE.LENGTH!)", "PYTHON")         gp.Addfield_management(lcp_name+".shp", "COST", "DOUBLE")         gp.CalculateField_management(lcp_name+".shp", "COST", cost1, "PYTHON")


The error I get is: arcgisscripting.ExecuteError: Error 9999999: Error executing function. The field is not nullable. [COST]. Failed to execute <Calculate field>

It creates the field "cost" but doesn't fill it. In ArcMap I open the shape and I'm able to fill it with zero value so I don't understand the error. 
Any suggestions??

Thanks a lot
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Occasional Contributor III
Try casting to string:

        gp.CalculateField_management(lcp_name+".shp", "COST", str(cost1), "PYTHON")

View solution in original post

0 Kudos
6 Replies
curtvprice
MVP Esteemed Contributor
ArcGIS version?

If you are using 10.0 or later, I highly recommend using arcpy, and using the PYTHON_9.3 parser.

10.0 - Calculate Field Exmples (Code samples--geometry)

Also, it's a good idea to avoid field names that are reserved words in SQL (i.e. LENGTH)
0 Kudos
JoshuaChisholm
Occasional Contributor III
I would also recommend throwing in a print cost1 before the CalculateField_management line just to check what value you are trying to insert.
0 Kudos
JasonScheirer
Occasional Contributor III
Try casting to string:

        gp.CalculateField_management(lcp_name+".shp", "COST", str(cost1), "PYTHON")
0 Kudos
JuanSerratosa_López
New Contributor
This is a section of a much bigger code that was made for ArcGIS 9.3 and Python 2.5, I'm trying to run it from ArcGIS 10.1 and Python 2.7. So this must be the problem in general...

But I tried what jscheirer suggested and it worked!!! Now the field gets populated with the correct information!! Thanks a lot.

Unfortunately the script stops without doing the last operation wich is to populate one single table with all this information.
Maybe I'll have to make a new post later... hehehehe

Thanks a lot for your advice and help!!!

Cheers!
0 Kudos
JoshuaChisholm
Occasional Contributor III
Hello Juan, I'm happy you got it working!

To help out the forums and future readers, I've marked Jason's response with a green check.
0 Kudos
JuanSerratosa_López
New Contributor
Thanks Joshua! I tried to mark it yesterday but couldn't...
0 Kudos