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?

  • Same issue with 3.12.3 as well.
    – GeorgeC
    Commented May 28, 2020 at 23:57
  • I can also confirm that i got this message today, with QGIS 3.14 . I only edited one record, however it has a large number of vertices.
    – nr_aus
    Commented Sep 1, 2020 at 7:36

4 Answers 4


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.


When you open a geopackage, a few hidden extra file appear next to it in the directory. That basically lock the file so that no other user can change it. While geopackage is a database, its limited to one user. In this case Python had a handle on the file. If python crashes, it can sometimes keep the handle on the file until you kill the process.


In QGIS open your layers, then in database manager make a connection with the geopackage, delete all the layers, it is going to be opened in your actual project, then export each one to the same geopackage, it's going to appear the new layer with another style, so I recommend you to save each style too. It works for me.


While this may not solve the problem itself, it's something that can save your polygons and hard work. What I did is simply selected the new polygons (lines, dots) and copied it. Then I made a new GeoPackage and pasted it into it. I have no idea why this error occurs but it doesn't mean you must lost your data.

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.