I have a problem to get parent child relations to work properly in QGIS. I have a parent table as polygon and two linked tables a non-spatial child_1 table and a second child_2 Point layer.
When I try to add child features to the parent layer I often get the followin error:
ERROR: invalid input syntax for type uuid: "uuid_generate_v4()"
My tables look like this:
CREATE TABLE test.parent ( gid serial NOT NULL, uid uuid NOT NULL DEFAULT uuid_generate_v4(), parent_txt text NULL, geom geometry(POLYGON, 3857) NULL, CONSTRAINT parent_pk PRIMARY KEY (uid) ); CREATE TABLE test.child_1 ( id serial NOT NULL, uid uuid NOT NULL, datum timestamp(0) NULL DEFAULT now()::timestamp without time zone, child_1_txt text NULL, CONSTRAINT child_1_pk PRIMARY KEY (id), CONSTRAINT child_1_fk FOREIGN KEY (uid) REFERENCES test.parent(uid) ON DELETE CASCADE ON UPDATE CASCADE ); CREATE TABLE test.child_2 ( id serial NOT NULL, uid uuid NOT NULL, datum timestamp(0) NULL DEFAULT now()::timestamp without time zone, child_2_txt text NULL, geom geometry(POINT, 3857) NULL, CONSTRAINT child_2_pk PRIMARY KEY (id), CONSTRAINT child_2_fk FOREIGN KEY (uid) REFERENCES test.parent(uid) ON DELETE CASCADE ON UPDATE CASCADE );
In QGIS all tables are loaded and two relations are set in the project properties using the uid field from the parent table to the uid (foreign key) of the child_1 or to the child_2 table.
In the autogenerated form to add or edit features, everything seems to be OK (see picture), but I still get the strange error about "uuid_generate_v4()" when trying to add new child features.
The strange thing is, that sometimes it works, but most of the time it fails. It fails, when I'm digitizing a parent feature and try to add immediately the child features. After saving the parent polygon and when I try to add child features it mostly fails with the mentioned error.
I followed the official documentation of QGIS to work with linked tables, but it seems, that I'm still missing something.