Skip to content
Back

unable to create createRelationshipAttribute to users

  • 0
  • Cloud
GitzJoey
23 Apr, 2025, 02:02

i make small test like so

` import { Client, Databases, ID, RelationshipType } from "node-appwrite";

const client = new Client(); client .setEndpoint("https://cloud.appwrite.io/v1") .setProject("68.......") .setKey("standard_21ab........");

const databases = new Databases(client);

(async () => { const databaseId = "68...........";

TypeScript
const collection = await databases.createCollection(
    databaseId,
    ID.unique(),
    "Test"
);

await databases.createStringAttribute(databaseId, collection.$id, "user_id", 36, true);
await databases.createRelationshipAttribute(databaseId, collection.$id, "user_id", "users", RelationshipType.OneToOne);

})(); `

The error message is

` throw new AppwriteException(data == null ? void 0 : data.message, response.status, data == null ? void 0 : data.type, responseText);

AppwriteException: Invalid type param: Value must be one of (oneToOne, manyToOne, manyToMany, oneToMany) at _Client.call (file:///config/workspace/DCSLab/node_modules/node-appwrite/dist/client.mjs:293:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async file:///config/workspace/DCSLab/test.js:23:5 { code: 400, type: 'general_argument_invalid', response: '{"message":"Invalid type param: Value must be one of (oneToOne, manyToOne, manyToMany, oneToMany)","code":400,"type":"general_argument_invalid","version":"1.6.2"}' } `

i tried using string "oneToOne" also throwing same error

TL;DR
Issue: Unable to create a Relationship Attribute for users using Appwrite's SDK Solution: The error is due to an invalid `type` parameter. Instead of using a string like "oneToOne," utilize the predefined constants provided by Appwrite for RelationshipType - in this case, `RelationshipType.OneToOne`, `RelationshipType.ManyToOne`, `RelationshipType.ManyToMany`, or `RelationshipType.OneToMany`.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more