Is there any way to refresh the attribute table of a layer after editing the table (e.g. add a column) in the DB-Manager?
3 Answers
Short and sweet:
- Install changeDataSource plugin.
- Right-click on the layer in the Layers Panel and select
Change vector datasource
. - In the dialog box that appears, just hit
OK
without changing any of the settings.
Basically, you are "changing" the vector datasource to what it already was, but this forces QGIS to reload the layer definition.
Tested in QGIS 2.14 on Linux Mint 17.2.
-
I've had to reselect the same datasource in order for that to work. Commented Jun 3, 2019 at 9:29
-
5 years later, this hasnt been automatically implemented in qgis 3 but this answer still works Commented Mar 26, 2021 at 9:55
Assuming that your working with a PostGIS database, you can update the statistics of the table of interest by using the ANALYSE
function:
http://www.postgresql.org/docs/current/static/sql-analyze.html
In your case you can execute the statement inside the DB-manager by pressing the button marked in the attached image and executing the ANALYSE
statement in the window, which is also marked. The query would be ANALYSE yourschema.yourtable
.The analyse command should update your table, so that when you access the information again it should reflect the changes you have made.
-
1This doesn't refresh the attribute table (right click on layer -> Open Attribute Table). Commented Apr 24, 2016 at 6:47
Do I understand well if you mean to refresh the table in QGIS after a change to the columns is made?
As far as I know, only close and open the project or re-adding the table will make this happen. As long as you saved the default style in the database that might be the fastest way.
When a column is added with the Field Calculator the changes are instantly visible but the DB manager offers more control in defining the field type so I understand why that may not be a solution.
-
Is there any Python command to refresh the attribute table? I've also noticed that 'Show Feature Count' ignores changes made in the DB-Manager (add features/delete features). Commented Apr 21, 2016 at 8:05
-
3
layer.dataProvider().forceReload()
should do the trick Commented Apr 26, 2016 at 9:09