I have a PostgreSQL database with a one-to-many relationship. Here is a reduced example:

CREATE TABLE buildings.building
  objectid serial NOT NULL,
  building_no character varying(40) NOT NULL,
  geometry geometry(Polygon,32638),
  CONSTRAINT building_pkey PRIMARY KEY (objectid)

CREATE TABLE buildings.flat
  objectid serial NOT NULL,
  fk_property_group integer,
  fk_building integer NOT NULL,
  CONSTRAINT flat_pkey PRIMARY KEY (objectid),
  CONSTRAINT flat_fk_building_fkey FOREIGN KEY (fk_building)
  REFERENCES buildings.building (objectid) MATCH SIMPLE

I defined a relationship in the QGIS (2.2 and 2.4) Project Properties and it looks good in the forms. But when I enter a new building I will have the value nextval('real_estate.property_group_objectid_seq'::regclass) for the objectid of the building and the flats that I want to add won't have the correct foreign key. Its actually NULL.

Is there any workaround/solution for this issue?

  • Did you try to save building table after adding new building (and reload the table)? I suppose it should help QGIS to use its primary key for form. I know, this should be a comment, but I can't comment yet. – Miloš Kroulík Aug 7 '14 at 8:32
  • I have quite some relations in other objects and saving the it each time would be very time consuming. You always have to close the form and open it again. For some i have a not null constraint, so I have to assign it in order to save it. – aleho Aug 8 '14 at 9:31

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.