create_relationship
Create relational links between Directus collections—m2o, o2o, o2m, m2m junction, or m2a—while generating the foreign keys and constraints those relationships require.
Instructions
Creates a relationship between collections together with the schema it needs: a m2o or o2o foreign key, an o2m reverse field, a m2m junction collection, or a m2a any-collection link. Use create_field for a plain non-relational column and analyze_relationships to see what already exists. Which parameters are required depends on type: m2m needs junction_collection and both junction fields, m2a needs allowed_collections and collection_field. Creates real tables and constraints and does not roll back when a later step fails, so a half-created m2m may need manual cleanup. on_delete and on_update set the referential actions, where CASCADE means deleting a parent deletes its children.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"type": "<type>",
"collection": "<collection>",
"field": "<field>"
},
"name": "create_relationship"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | Yes | Relationship type | |
| field | Yes | Source field | |
| on_delete | No | On delete action | |
| on_update | No | On update action | |
| collection | Yes | Source collection | |
| sort_field | No | Sort field | |
| related_field | No | Target field | |
| junction_field | No | Junction field (M2M only) | |
| collection_field | No | Collection field (M2A only) | |
| primary_key_field | No | Primary key field (M2A only) | |
| related_collection | No | Target collection | |
| allowed_collections | No | Allowed collections (M2A only) | |
| junction_collection | No | Junction collection (M2M only) | |
| related_junction_field | No | Related junction field (M2M only) |