I have a vector layer to which I want to apply some constraints using a script with PyQGIS (a NOT NULL constraint on some fields).
I checked the docs of PyQGIS and found
setConstraintExpression (int index, const QString &expression, const QString &description=QString()) which as I understand it from the docs it applies to a
QgsVectorLayer I used it in my code like this:
my_layer = QgsVectorLayer('./path/to/my_layer.shp', 'my_layer', 'ogr') field_index = my_layer.fieldNameIndex('ID') my_layer.setConstraintExpression(field_index, 'NOT NULL')
I get an error that the function does not exist :
> AttributeError: 'QgsVectorLayer' object has no attribute > 'setConstraintExpression'
I also tried
setFieldConstraint and I get the same error. How can I add a constraint on a field using PyQGIS? (QGIS 2.18 Las Palmas)
I've just noticed that these 2 methods I tried are in the QGIS API 2.99.0-Master which is still not released.