drizzle-team/drizzle-orm · error · Error

unsupported relation type

Error message

unsupported relation type

What it means

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.

Source

Thrown at drizzle-kit/src/serializer/studio.ts:560

					if (is(refTable, PgTable)) {
						refSchema = pgTableConfig(refTable).schema;
					} else if (is(refTable, MySqlTable)) {
						refSchema = mysqlTableConfig(refTable).schema;
					} else if (is(refTable, SQLiteTable)) {
						refSchema = undefined;
					} else if (is(refTable, SingleStoreTable)) {
						refSchema = singlestoreTableConfig(refTable).schema;
					} else {
						throw new Error('unsupported dialect');
					}

					let type: 'one' | 'many';
					if (is(rel, One)) {
						type = 'one';
					} else if (is(rel, Many)) {
						type = 'many';
					} else {
						throw new Error('unsupported relation type');
					}

					return {
						name,
						type,
						table: it.dbName,
						schema: it.schema || 'public',
						columns: fields,
						refTable: refTableName,
						refSchema: refSchema || 'public',
						refColumns: refColumns,
					};
				} catch {
					throw new Error(
						`Invalid relation "${relation.fieldName}" for table "${
							it.schema ? `${it.schema}.${it.dbName}` : it.dbName
						}"`,
					);

View on GitHub (pinned to b7862528fd)

Solutions

  1. Open the named relation's declaration and ensure every property is built with `one()` or `many()`.
  2. Remove any computed/non-relation fields from the relations callback.
  3. Re-run `drizzle-kit studio` after fixing the declaration.

Example fix

// before
relations(users, () => ({
  posts: { table: posts } as any, // not a relation builder
}));
// after
relations(users, () => ({
  posts: many(posts),
}));
Defensive patterns

Strategy: type-guard

Validate before calling

// Static lint: every value in a Relations callback must be one()/many()
import { One, Many } from 'drizzle-orm/relations';

Type guard

import { is } from 'drizzle-orm';
import { One, Many } from 'drizzle-orm/relations';

function isValidRelationValue(v: unknown): v is One | Many {
  return is(v, One) || is(v, Many);
}

Try / catch

try {
  await startStudio(schema);
} catch (e) {
  if ((e as Error).message.includes('unsupported relation type')) {
    // inspect each relations() callback for non one()/many() entries
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03). Data as JSON: /data/errors/a350d5522db6c9a1.json. Report an issue: GitHub.