I have a .qgz project with a spatial layer and two non-spatial layers, primarily created for data collection. All the three layers are saved in a single .gpkg file and the non-spatial layers are related to the spatial layer by Relations created in Project Properties and it works fine.

Now, I want to use these layers with their relations and Form layout in another master project. For this, I tried exporting the layer style as .qml file (including relations) and then loaded the data and the style file in the master project. While I am able to see the desired form layout, the relations are not appearing. I know I can create relations again in the new project but I am looking for a seamless way to get the job done.

Am I missing something here? Or does it not work this way?

Qgis 3.28 & Windows 11

  • I didn't try it but recent (don't remember witch version) QGIS let you create relation directly in your geopackage. Since 3.28 relation should be automatically used if present in your GPKG (qgis.org/zh-Hans/site/forusers/visualchangelog328/… ; qgis.org/zh-Hans/site/forusers/visualchangelog328/…)
    – J.R
    Commented Dec 21, 2023 at 14:36
  • Forgot to mention that I am using version 3.28 currently. The method you have mentioned does the packaging of related layers in addition to to those selected for packaging. I have already tried that and it didn't serve my purpose.
    – Abhijith
    Commented Dec 21, 2023 at 17:09
  • While the packaging is indeed a new feature of 3.28 there is two other new feature relevant to your case "Feature: Automatically add related tables when adding layers from GDAL datasets with embedded relationship information" and "Feature: Implement relationship discovery for OGR layers, and show relationships in browser". Try to create the relation in the data source provider (select your gpkg, right click and select create new relationship)
    – J.R
    Commented Dec 21, 2023 at 17:20
  • Relationship discovery apparently works with the relations defined by FOREIGN KEY only.
    – Abhijith
    Commented Mar 16 at 18:16

1 Answer 1


After trying all possible ways, I have found one work around for this.

The Relations created within a QGIS project from Project Properties is saved in the .qgz file and is not embedded with the .gpkg. However, the layer style .qml file does contain some partial information, which is not useful anyways. You will see a blank relation in the Form Layout.

The solution here is to embed the project file with the relations inside the master project file using Layer > Embed Layers and Groups. By this way, all Relations, Form Layouts and Styles are embedded in the master project. However, you cannot access layer properties of embedded layers from the master project. For that you need to duplicate the layers within the master project or change properties within the original project file.

PS: You have to make sure the directories of both projects are portable together while maintaining the relative paths.

  • Thanks for the Input! So I have a "Master Project" where I want to I import a "template-Project". This works for vector joins and relationships. Unfortunately, the strength of relationships is set to "Association" in the "Master Project" instead of "Composition" as in the "template-Project". I don't know whether that's a problem. Furthermore: Putting those layers to QField via QFieldSync doesn't seem to work. The QField project still points to the original files, while creating a copying of the data next to the QField project...
    – Beni
    Commented Apr 4 at 14:10

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.