[Featureserver] PostGIS insert fails due to null value in column "gid"

Sacha Black sacha.black at gmail.com
Thu Sep 4 20:34:23 EDT 2008


With the tips from Andrew and Yves, the demo is working as expected
(in Win XP via apache and python 2.5), with the default scribble DBM.

Now I have created a scribblePG which is connected to a PostGIS layer:

[scribblePG]
type=PostGIS
dsn=host=localhost dbname=xxxx user=xxxx password=xxxx
layer=xxxx_scribble
fid=gid
geometry=wkb_geometry
gaping_security_hole=yes

I think the connection is working fine because when I check like this:

http://localhost/featureserver/featureserver.cgi/scribblePG/all.gml

I get a gml record containing the expected 2 polygons from the layer.
I assume this means that my psycopg2 is installed correctly.

However, when I modify the demo to use my scribblePG layer, I am
missing something. Because while I can see the scribblePG layer
drawing on my map in OpenLayers, I can't seem to write new polygons to
the layer.

When I draw a new polygon on the map and hit "upload to server" I get
the "Features uploaded to server." success message. No Javascript
errors are reported in Firefox. Yet the polygon is not saved to the
scribblePG layer at all, and disappears from the map as soon as the
"upload to server" button is pushed.

Andrew suggested that this might be a simplejson problem, but I think
that the demo would not have worked if simplejson was not working.

Instead the error have seems to be related to the fact that I am not
passing a new feature id to PostGIS. The error as reported in the
Apache error log looks like this:

An error occurred: null value in column "gid" violates not-null constraint\r
File "\\FeatureServer\\Server.py", line 298, in cgiHandler\r
format, content = service.dispatchRequest( params, path_info, host,
post_data, request_method, accepts )\r
File "\\FeatureServer\\Server.py", line 145, in dispatchRequest\r
result = method(action)\r
File "\\FeatureServer\\DataSource\\PostGIS.py", line 142, in create\r
cursor.execute(str(sql), self.feature_values(feature))\r

I tried to address this by passing a hidden key/value pair from the
HTML side like so:

        <input type="hidden" id="key3" value="gid" /><input
type="hidden" id="value3" value="2" /> <br />

but this didn't seem to make any difference at all, and I guess that
makes sense as the gid value is the internal feature id that is not
normally edited by the user (I think?). The gid field is required
(it's a primary key), and required to not be null.

So my question is : how do I get an automatic sequential number to
insert into the gid field ? Or am I going in the wrong direction here
?

Sacha



More information about the Featureserver mailing list