I have set up a spatial database in PostgreSQL in which I have some data/tables that need to be linked by M to N relations. For those occasions I have two tables that contains geometry and a pivot table that contains foreign keys of both tables.
I tried to set up QGIS (3.10) in the way the manual insist for working with M to N relations. I have loaded the relations in project properties and I can see it in the attribute form when I identify the feature. I have already created features in one layer and now I would like to create features in other layer and link it. When I try to set up the link in the attribute form of the new feature I encounter an error:
ERROR: insert or update on table "park_usek" violates foreign key constraint "fk_park" DETAIL: Key (fk_park)=(18) is not present in table "park_pol".
I understand that it's because the foreign key in the pivot table can't be directed to the ID of the new feature as it hasn't yet been created. Is there any way I can set QGIS and/or PostgreSQL (via PgAdmin4) so it should fire this only after the creation of the feature or something like this? I understand that I can probably write a script which would handle this, is there is an easier solution?