{"id":"a350d5522db6c9a1","repo":"drizzle-team/drizzle-orm","slug":"unsupported-relation-type","errorCode":null,"errorMessage":"unsupported relation type","messagePattern":"unsupported relation type","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-kit/src/serializer/studio.ts","lineNumber":560,"sourceCode":"\t\t\t\t\tif (is(refTable, PgTable)) {\n\t\t\t\t\t\trefSchema = pgTableConfig(refTable).schema;\n\t\t\t\t\t} else if (is(refTable, MySqlTable)) {\n\t\t\t\t\t\trefSchema = mysqlTableConfig(refTable).schema;\n\t\t\t\t\t} else if (is(refTable, SQLiteTable)) {\n\t\t\t\t\t\trefSchema = undefined;\n\t\t\t\t\t} else if (is(refTable, SingleStoreTable)) {\n\t\t\t\t\t\trefSchema = singlestoreTableConfig(refTable).schema;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('unsupported dialect');\n\t\t\t\t\t}\n\n\t\t\t\t\tlet type: 'one' | 'many';\n\t\t\t\t\tif (is(rel, One)) {\n\t\t\t\t\t\ttype = 'one';\n\t\t\t\t\t} else if (is(rel, Many)) {\n\t\t\t\t\t\ttype = 'many';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error('unsupported relation type');\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tname,\n\t\t\t\t\t\ttype,\n\t\t\t\t\t\ttable: it.dbName,\n\t\t\t\t\t\tschema: it.schema || 'public',\n\t\t\t\t\t\tcolumns: fields,\n\t\t\t\t\t\trefTable: refTableName,\n\t\t\t\t\t\trefSchema: refSchema || 'public',\n\t\t\t\t\t\trefColumns: refColumns,\n\t\t\t\t\t};\n\t\t\t\t} catch {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Invalid relation \"${relation.fieldName}\" for table \"${\n\t\t\t\t\t\t\tit.schema ? `${it.schema}.${it.dbName}` : it.dbName\n\t\t\t\t\t\t}\"`,\n\t\t\t\t\t);","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-kit/src/serializer/studio.ts#L542-L578","documentation":"Thrown by Studio relation extraction when a relation object is neither `One` nor `Many`. drizzle's relational API only supports those two relation builders, so any other value inside a table's `Relations` declaration is invalid.","triggerScenarios":"Defining `relations(table, () => ({ ... }))` with a field that returns something other than `one()` or `many()`, e.g. a raw column, an arbitrary object, or a misused helper.","commonSituations":"Hand-editing relation definitions, using a deprecated/renamed helper, or a schema that imports the wrong builder. Because the outer `try` wraps this, it is normally re-thrown as 'Invalid relation' (error 5), but the root cause is here.","solutions":["Open the named relation's declaration and ensure every property is built with `one()` or `many()`.","Remove any computed/non-relation fields from the relations callback.","Re-run `drizzle-kit studio` after fixing the declaration."],"exampleFix":"// before\nrelations(users, () => ({\n  posts: { table: posts } as any, // not a relation builder\n}));\n// after\nrelations(users, () => ({\n  posts: many(posts),\n}));","handlingStrategy":"type-guard","validationCode":"// Static lint: every value in a Relations callback must be one()/many()\nimport { One, Many } from 'drizzle-orm/relations';\n","typeGuard":"import { is } from 'drizzle-orm';\nimport { One, Many } from 'drizzle-orm/relations';\n\nfunction isValidRelationValue(v: unknown): v is One | Many {\n  return is(v, One) || is(v, Many);\n}","tryCatchPattern":"try {\n  await startStudio(schema);\n} catch (e) {\n  if ((e as Error).message.includes('unsupported relation type')) {\n    // inspect each relations() callback for non one()/many() entries\n  }\n  throw e;\n}","preventionTips":["Only use one() and many() inside relations() callbacks.","Run `tsc --noEmit` on the schema to catch accidental non-relation values."],"tags":["drizzle-kit","studio","relations","schema"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}