I have just ran into an issue with QGIS/PostGIS. Here is a summary of my problem:

  1. I have uploaded a world country boundaries shapefile as a PostGIS table to my database.
  2. I add the new PostGIS table to QGIS as a layer.
  3. I toggle editing for the table so that I may edit the file.
  4. I click on "New Field" and enter "test" as the field name, leaving everything else default.
  5. I click "OK" and the following error message pops up: "Failed to add field 'test' of type 'int2'. Is the field name unique?"
  6. There is no other field named "test", and no other field name works.

All the googling I have done on SE/SO and this sub have left me empty handed. Does anyone have an idea as to why I cannot add a field to this PostGIS table?

At first I thought it may have been a privilege issue with Postgres but I double checked the login role that I used has insert/update/delete privileges. Additionally, I connected to the database using the superuser credentials and had the same issue. For reference, I am using QGIS 2.18.9 with Win7 x64.

Also, some additional information: When I toggle editing for the table, the "Delete field" button is still grayed out, which I thought was odd as usually that button is usable when editing is toggled on. Not sure if that's helpful or not.

  • 2
    Are you able to perform any other edits to the table, ie. can you add a test feature? Wondering if you're lacking a primary key that would prevent any table editing? – DPSSpatial Jul 11 '17 at 20:23
  • Interestingly, no, I cannot add a new feature. When I toggle editing and try to draw a new polygon, I get the following error: "Add feature: line 0 contains 1 duplicate node(s) at 2 Geometry has 1 errors. Validation finished" and it fails to add the new polygon. Looking at the table in PgAdmin 3, it does have a primary key (gid). – blwoods Jul 11 '17 at 20:29
  • 2
    sounds like user permission see the related post gis.stackexchange.com/questions/31244/… – Mapperz Jul 11 '17 at 21:49
  • 1
    Can you add/alter a field with your credentials in postgres command line or PgAdmin? If you can't add a field, new features (rows) or delete features it definitely sounds like you don't have permission on the table as @Mappers said. How did you create the database? How did you upoload? Have you created databases and tables before in this cluster and if so did they respond correctly? Has anything changed since last time? – Michael Stimson Jul 11 '17 at 22:05
  • 2
    I hope it doesn't sound stupid, but are you double-clicking to end the feature drawing? The error message looks like it. I made the same mistake once and it took a few minutes to realize it... – TurboGraphxBeige Jul 12 '17 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.