New to python, and been looking at this for a while, trying to write a scrip to automate a process we need to carry out in QGIS a few thousand times. As part of this I need to create a feature into an existing Postgres table without geometry. The existing table has approximately 40 different columsn, however I only need to populate the 6 as shown in the code.
I have the below code which I believe is correct, however the add features command doesnt seem to work, it returns False and doesnt write anything to the datbase.
def createNewIntermentRightRecord(layer,cemetery,yearsGranted,surname,firstName,otherName,liscadNo):
if internRightsCaps & QgsVectorDataProvider.AddFeatures:
feat = QgsFeature(layer.pendingFields())
feat.initAttributes(6)
feat.setAttributes(['Cemetery',cemetery])
feat.setAttributes(['Years Granted',yearsGranted])
feat.setAttributes(['IR Holder - LAST NAME',surname])
feat.setAttributes(['IR Holder - First Name',firstName])
feat.setAttributes(['IR Holder - Other Name/s'])
feat.setAttributes(['Liscad Polygon No',liscadNo])
(res,outFeats) = layer.dataProvider().addFeatures( [ feat ] )
print res
print outFeats