[GIS] QGIS: OGR error when editing Geopackage layers : database is locked

geopackageogrqgisqgis-3qgsvectorlayer

I started to draw new polygons in a layer within an existing GeoPackage that I previously created.

However, after editing several layers, I sometimes (apart that it doesn't happen when editing one single layer, it looks like a random phenomena) cannot save the layer and I get the error:

Errors: ERROR: feature(s) not added.

Provider errors: 
  OGR error creating feature: failed to execute insert : database is locked

The polygons drawn are then lost, which is pretty frustrating.

I googled a lot and found this rather old fix which is apparently already applied in QGIS 3.12 (my version).

Any suggestion?

Best Answer

ok unfortunately I performed 2 different resolution activities, and im not sure which activity resolved the problem.

First Action - I had previously run a python script (outside of QGIS) which had completed, but it had used the Geopackage (a different table though). I simply closed this python console window (maybe the console or process that ran inside the console had locked the DB?)

Second action - In QGIS, i went to Database > DB Manager and 'Reconnected' the database. I then reloaded the layer inside of my QGIS session, made an edit and saved. all good.

So - whether it was the first or second action. not sure.

Related Question