I have a simple table with an id field and a polygon field in mySql. Using QGIS I can add new polygons and give them an id. Before saving them I can also edit them.

But once a polygon has been saved it cannot be edited any more: every time I move it, it simply moves back to the original position when I save the edits. Added points disappear when saving.

The same happens with a point field in a different table.

What could be the problem?

  • Just a shot in the dark, but you might open your poly table and see if MySQL recognizes the id as both Primary Key (PK) and Auto Incrementing (AI). If you don't have PK specified on your intended id value, I could forsee that giving you some grief. ..sorry if that's not it. :/
    – elrobis
    Dec 21, 2012 at 11:36
  • 1
    That was it! It was Primary Key but not Auto Incrementing. I had no idea this was required. Thanks a whole lot, elrobis! How can I mark your answer as the accepted?
    – Alex
    Dec 21, 2012 at 19:04
  • No problem---I'm glad that did the trick. And welcome to the site. I'll just copy/paste the comment into an answer and you can accept it.
    – elrobis
    Dec 21, 2012 at 19:09

1 Answer 1


I've noticed that ogr2ogr, when it imports and creates MySQL tables, does not flag the OGR_FID field as Primary Key (PK) and/or Auto Increment (AI)---I forget which it is. But as you found out, it seems QGIS has a similar behavior.

With ogr2ogr, I usually experience this as MySQL Workbench complaining that it cannot edit the data, and I fix this by opening the table to ALTER it, and making sure the OGR_FID field is flagged for both PK and AI.

It sounds like applying this solution against QGIS/MySQL also did the trick for you. Good deal---I'm happy it was that simple. 8)

  • Alex, out of curiosity, did you create the table/layer directly within QGIS, or did you import it using another method?
    – elrobis
    Dec 21, 2012 at 19:28
  • 1
    I created the tables in on my Webserver on mySql, then added them as vectorlayer. What I have learned: the table needs a Primary Key and Auto Incrementing. AND: It only works with one (the first) geometry field - more are ignored and when I present them with a view editing does not work.
    – Alex
    Dec 21, 2012 at 19:57

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.