[QGIS-Developer] [Qgis-developer] $id not working as default value

DelazJ delazj at gmail.com
Fri Mar 16 07:31:25 PDT 2018


Hi Nyall,


2016-12-27 2:03 GMT+01:00 Nyall Dawson <nyall.dawson at gmail.com>:

> On 23 December 2016 at 23:37, Paolo Cavallini <cavallini at faunalia.it>
> wrote:
> > Il 23/12/2016 14:32, Giovanni Manghi ha scritto:
> >
> >> The solution from the Gitter discussion
> >>
> >> aggregate( 'layername','max',"id")+1
> >
> > thanks Giovanni
> >
> >> We need of course a more user friendly way to allow users have
> >> incremental/serial ids in their shapefiles...
> >
> > sure, e.g. a named preset expression, as previously suggested.
> > all the best.
>
> In master you can add UNIQUE and NOT NULL constraints to the field
> from within QGIS. This will cause QGIS to automatically populate it
> with a serial type value whenever a new feature is created.
>
>
How does this work? I thought to document this tip in the User manual and
wanted to give it a try before but always fail:
I created an integer field which is recognized in the Attribute Forms
dialog as a range
I checked "unique" and "not null" constraints (and unchecked "allow null
values" from the range widget properties)
The first created feature had value =0
The second one also got 0 with the yellow cross on the side But changes
(with two 0 values) are saved in the layer.
Enforcing the constraints do not help, neither do setting the widget as
"Text Edit".

Did I miss something (btw i'm using a temporary layer but also failed with
shapefile) or is it broken.
Any help is welcome.

Thanks,
Harrissou



> Nyall
>
>
> > --
> > Paolo Cavallini - www.faunalia.eu
> > QGIS & PostGIS courses: http://www.faunalia.eu/training.html
> > https://www.google.com/trends/explore?date=all&geo=IT&q=qgis,arcgis
> > _______________________________________________
> > Qgis-developer mailing list
> > Qgis-developer at lists.osgeo.org
> > List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> > Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180316/70f135fc/attachment.html>


More information about the QGIS-Developer mailing list