I'm trying to add multiple fields to a geopackage layer and set their aliases at the same time. It is working on a temp layer but not on the geopackage, why?
lyr = iface.activeLayer()
p = lyr.dataProvider()
fl = [['grtr_spr_t',QVariant.Int,'test'], #name, type, alias
['grtr_spr_g',QVariant.Int, 'test2'],
['grtr_spr_l',QVariant.Int, 'test3']]
fieldlist = [QgsField(f[0], f[1]) for f in fl] #Create a list of QgsFields
for e, data in enumerate(fl):
fieldlist[e].setAlias(data[2]) #Set the aliases of them
#[f.alias() for f in fieldlist]
#['test', 'test2', 'test3'] #They are set
p.addAttributes(fieldlist)
lyr.updateFields()
lyr.setFieldAlias(1,'test')
and then I seelyr.attributeAliases() {'fid': '', 'grtr_spr_t': 'test'}
. "test" shows also when I open the attribute table from TOC.