[Qgis-user] Saving values by a Python-Script in a PostgreSQL-Database

Kai Borgolte Kai.Borgolte at gmx.de
Mon May 27 12:53:46 PDT 2019


Hi Kai,

you can get messages from PostGIS by calling commitErrors():

if vlayer2.commitChanges():
    print('ok commitChanges')
else:
    print('not ok commitChanges')
    for l in vlayer2.commitErrors():
        print(l)

The messages gave me a subtle hint that the attribute definition has to
be more complete:

if vlayer2.addAttribute(QgsField(my_field_name2, QVariant.String,
'text', -1, -1)):
    print('ok AddAttribute')

After this change commitChanges() succeeds. updateFields() continues to
fail without message. I think you don't need updateFields() because you
don't modify fields directly on the provider.
--
Kai Borgolte, Bonn


More information about the Qgis-user mailing list