Empty Schema Value Causes Schema Apply Failure
Using Directus 9.21.* When exporting the schema of a collection, the schema value is empty, which seems to cause relationships to fail. When I add the name of the collection to the schema value in the JSON, I can apply the schema without errors.
Example Exported Collection
"collections": [ { "collection": "test_collection_2", "meta": { "collection": "test_collection_2", "icon": null, "note": null, "display_template": null, "hidden": false, "singleton": false, "translations": null, "archive_field": "status", "archive_app_filter": true, "archive_value": "archived", "unarchive_value": "draft", "sort_field": null, "accountability": "all", "color": null, "item_duplication_fields": null, "sort": 68, "group": null, "collapse": "open" }, "schema": {} } removed fields and relations ]
When I use the above with npx directus schema apply ./file.json I get the following error:
ERROR: Failed to create relation "test_collection_2.image"
ERROR: Invalid payload. Collection "test_collection_2" doesn't exist.
err: {
"type": "",
"message": "Invalid payload. Collection \"test_collection_2\" doesn't exist.",
"stack":
DirectusError: Invalid payload. Collection "test_collection_2" doesn't exist.
at RelationsService.createOne (file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/services/relations.js:119:19)
at file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/utils/apply-diff.js:206:44
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
"name": "DirectusError",
"extensions": {
"reason": "Collection \"test_collection_2\" doesn't exist"
},
"code": "INVALID_PAYLOAD",
"status": 400
}
After changing schema to be:
"schema": {"name": "test_collection_2"}
The apply works.
Maybe this is more of a Directus issue with the data coming out of the API? Thank you for considering this.
Hi @syoumans
I followed the guide in the documentation to set the schema field to an empty object when exporting.
So with "schema": {}, it should not cause any errors. I also tested on 9.21.0 and no bugs have been detected so far.
Without much context (i.e. where does the image field come from), I can't be sure about the root cause.
If it still troubles you, could you give me more info about your schema in a reproducible way?
Interesting. Thank you for checking! We're upgrading to 10.x now; I'll report back shortly.