I often have to reload layers in the layers panel after doing changes in the DB-Manager (add a column, delete a default value, ...). At the moment I use the changeDatasource plugin. Can this also be done using Python?
I've read several answers for this specific question; none of them seems to work. The only effective solution I could find is:
layer.setDataSource( layer.source(), layer.name(), layer.providerType() )
Tested in QGIS v2.14.8.
if you have your layer as a variable, simply
You can obtain a list of all layers of the current project from
If you don’t care about reloading all other layers at the same time, the one-liner
does the job, too.