layer.renameAttribute(0,'xxx') Traceback (most recent call last): File "", line 1, in AttributeError: 'QgsVectorLayer' object has no attribute 'renameAttribute'
Can you get me solution for this error?
layer.renameAttribute(0,'xxx') Traceback (most recent call last): File "", line 1, in AttributeError: 'QgsVectorLayer' object has no attribute 'renameAttribute'
Can you get me solution for this error?
I had the same issue. Try this piece of code. It worked for me.
layer = iface.activeLayer()
for field in layer.pendingFields():
if field.name() == 'old':
with edit(layer):
idx = layer.fieldNameIndex(field.name())
layer.renameAttribute(idx, 'new')