title: How to add fields to postgis layer loaded in qgis
body: <p>I have loaded the layer from Postgis in qgis and i am adding the fields to the layer using the follo code snippet:</p>
  
  <pre><code>canvas = qgis.utils.iface.mapCanvas()
  aLayer = canvas.currentLayer()
  field_name = "test"
  
  aLayer.startEditing()
  if not field_name in fieldnames:
        res = aLayer.dataProvider().addAttributes([QgsField(field_name, QVariant.String)])
  aLayer.updateFields()
  aLayer.commitChanges()
  </code></pre>
  
  <p>but it is not adding the field to the layer. What i have to do if i want to add the fields to the layer.</p>