We have a QGIS project with a parent (parquets) and two child layers (peuplements and gestion) (1:n relation) all stored in PostGIS. The parent primary key is a UUID (no default value defined). Both child layers use an UUID field as foreign key. Foreign key constraints are set properly in PostGIS.

In QGIS relations are set and the parent uuid has an uuid() function in the attribute field set as default. (We do not use the built-in UUID-generator.)

enter image description here

enter image description here

enter image description here

In QGIS we can digitize new parent polygons, add multiple children and save everything back to the database.

When using the project in QField we are able to digitize new polygons and add child layers. When trying to sync back to QGIS only the parent polygons are imported and we run in the following error:

insert or update on table "parquets" violates foreign key constraint "peuplement_fk" DETAIL: Key (uuid)=(24fdfc80-2f1e-44fb-8dd8-d492901c37de) is not present in table "parquets".

This behavior is correct. When I look in the attribute table of the parent layer in PostGIS, all the UUIDs are new ones. So none of the children can be imported since they all keep the old UUIDs from QField.

Did we miss something?

QGIS 3.16.7

QField 1.9.5 (5f66b7v1.9.5)

  • That checkbox at the bottom of the last image, is that the one for "apply default on update"? Could that have something to with it? You only want the default on creation not update.
    – M Bain
    May 27, 2021 at 10:13
  • Well we tried that already, but we uncked the "apply default on update" and gave it a new try. Now at least the first child (peuplements) is imported when trying to sync back to QGIS. We still get the same error for the second child layer: insert or update on table "gestion" violates foreign key constraint "gestion_fk" DETAIL: Key (uid)=(51ccac98-a32d-41c2-b9b3-c4beed1327da) is not present in table "parquets".
    – geom
    May 27, 2021 at 21:19
  • Odd, please keep us updated if you get to the bottom of it. I'm about to start using QField for some vegetation survey work. I have followed the QField guide for captuing multiple child records (photos) using UUID with default value. I will end up with a similar setup to you, only with geopackage instead of PostGIS. In the QField docs they set the strength of the relation as Composition not Association - I don't know what the difference is...
    – M Bain
    May 27, 2021 at 21:28
  • 1
    Here You have an answer to the difference between composition and association
    – geom
    May 27, 2021 at 21:54
  • I checked the data.gpkg from QField and there all the UUID's match, means the generated parents UUID's are the same as the related children UUIDs. After synchronisation of the QField data.gpkg to QGIS the correct UUIDs are stored in the PostGIS database. Only the second layer (gestion) cannot be imported. So it seems that this is an issue of the order how the data is synced to the database. When a child layer is intended to be imported before the parent layer exists, the import fails. It seems that there is no predictable order in which the datasets are imported.
    – geom
    May 27, 2021 at 22:17

1 Answer 1


At the end we figured out, that QFieldSync seems to respects the alphabetical order of the layer names while synchronizing.

We added an alias to our parent layer (changed parquets => _parquets). In this case the parent layer is situated as first layer in alphabetical order. At this point we didn't encounter any issues while synchronizing our project.

We admit, that it is a quick and dirty workaround, but until it get fixed, it could help poeple to enjoy the power of QField. Here also the related post on Github.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.