bcc-code / directus-schema-sync

The better way to sync your Directus schema and data between environments
Apache License 2.0
90 stars 4 forks source link

Cannot import due to `INVALID_FOREIGN_KEY - Invalid foreign key for field "project_logo" in collection "directus_settings"` #42

Closed add-n2x closed 3 weeks ago

add-n2x commented 4 weeks ago

Describe the Bug

First of all - thanks for building such a great extension!

I'm just getting started and I'm not able to import due to an INVALID_FOREIGN_KEY - Invalid foreign key for field "project_logo" in collection "directus_settings" error.

In the schema-sync docs I could not find any info on how to deal with uploads and if they are also synced. I have even tried copying the uploads folder manually. But no success.

To Reproduce

I have done an export using:

docker compose exec -it directus npx directus schema-sync export

Then on the remote machine I did:

docker compose exec -it directus npx directus schema-sync import
[11:43:07.048] INFO: Loaded extensions: directus-extension-schema-sync
[11:43:07.054] INFO: Importing everything from: /directus/schema-sync/data
[11:43:07.074] INFO: Stitched 18 partial schema files
[11:43:07.370] ERROR: Failed loading "directus_settings".
[11:43:07.370] ERROR: Failed loading "directus_permissions".
[11:43:07.370] ERROR: Failed loading "directus_folders".
[11:43:07.370] ERROR: Failed loading "directus_roles".
[11:43:07.370] ERROR: Failed loading "schema".
[11:43:07.370] ERROR: Invalid foreign key for field "project_logo" in collection "directus_settings".
    err: {
      "type": "",
      "message": "Invalid foreign key for field \"project_logo\" in collection \"directus_settings\".",
      "stack":
          DirectusError: Invalid foreign key for field "project_logo" in collection "directus_settings".
              at foreignKeyViolation (file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_crtpmuhomzjtudzfxjp6matirq/node_modules/@directus/api/dist/database/errors/dialects/postgres.js:87:12)
              at extractError (file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_crtpmuhomzjtudzfxjp6matirq/node_modules/@directus/api/dist/database/errors/dialects/postgres.js:21:20)
              at translateDatabaseError (file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_crtpmuhomzjtudzfxjp6matirq/node_modules/@directus/api/dist/database/errors/translate.js:26:28)
              at file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_crtpmuhomzjtudzfxjp6matirq/node_modules/@directus/api/dist/services/items.js:154:29
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async ItemsService.createOne (file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_crtpmuhomzjtudzfxjp6matirq/node_modules/@directus/api/dist/services/items.js:86:28)
              at async file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_crtpmuhomzjtudzfxjp6matirq/node_modules/@directus/api/dist/services/items.js:275:36
      "name": "DirectusError",
      "extensions": {
        "collection": "directus_settings",
        "field": "project_logo"
      },
      "code": "INVALID_FOREIGN_KEY",
      "status": 400
    }
make: *** [Makefile:46: sync] Fehler 1

Version

directus-schema-sync 2.1.1 directus 10.12.0

Installed Extension Via

Docker file

u12206050 commented 3 weeks ago

Sounds like the corresponding file isn't exported/imported before this row is added. Are you exporting directus_files? Which could be a problem since you probably don't have the file locally or?

u12206050 commented 3 weeks ago

Closing this due to possibly incorrect configuration.

add-n2x commented 3 weeks ago

Sounds like the corresponding file isn't exported/imported before this row is added. Are you exporting directus_files? Which could be a problem since you probably don't have the file locally or?

Not sure. Your docs do not mention such setting. I am just using the defaults.

Can you please point me to where and what needs to be configured?

Edit: I did also manually copy all the files.

jstet commented 1 week ago

I put the files belonging to the directus styling in a folder (via directus ui), then added this to 'directus_config.js`:

directus_files: {
        watch: ['files'],
        excludeFields: ["modified_by", "uploaded_by"],
        query: {
            filter: { folder: { id: { _eq: "d169b6d9-9e72-4adc-aaca-548fa22aeab5" } } },
        },
    },

id equals this folders id.

Afterwards, loop over the exported files json to download the files from the server where u exported files from and use the update file endpoint to add the file data to the server where u want to import to