18

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?

1
  • the changeDataSource plugin is the fastest way and works very well with .csv files
    – scataldi
    Commented Oct 10, 2017 at 12:25

3 Answers 3

19
+50

Short and sweet:

  1. Install changeDataSource plugin.
  2. Right-click on the layer in the Layers Panel and select Change vector datasource.
  3. 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.

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
    – Luffydude
    Commented Mar 26, 2021 at 9:55
4

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. DB manager window

1
  • 1
    This doesn't refresh the attribute table (right click on layer -> Open Attribute Table).
    – Lunar Sea
    Commented Apr 24, 2016 at 6:47
2

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.

2
  • 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).
    – Lunar Sea
    Commented Apr 21, 2016 at 8:05
  • 3
    layer.dataProvider().forceReload() should do the trick Commented Apr 26, 2016 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.