I am trying to copy and paste point features from one table to an existing PostGIS table, but I get a NOT NULL, Unique error for the id field (below). How can I update the PostGIS table with new data created in QGIS?
QGIS version 3.22.4-Białowieża
I am trying to copy and paste point features from one table to an existing PostGIS table, but I get a NOT NULL, Unique error for the id field (below). How can I update the PostGIS table with new data created in QGIS?
QGIS version 3.22.4-Białowieża
One way to do it, from the postgis side, is to add a new serial column and set it as the primary key:
alter table your_table add column pk serial primary key;
This will provide QGIS the next sequence value as the pk when you add new features.
You can also alter your existing id column like this:
create sequence your_table_id_seq;
alter table your_table alter column id set default nextval('your_table_id_seq');
select max(id) + 1 from your_table; -- use this value in the next part
alter sequence your_table_id_seq
minvalue 100 -- change this number to the max(id) + 1 value
start 100 -- also change this number
restart 100 -- and this number
You might also need to make the id column the primary key:
alter table your_table add primary key (id);