drizzle-team/drizzle-orm · error · Error
Your "${f.path.join('->')}" field references a column "${tab
Error message
Your "${f.path.join('->')}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it? What it means
Thrown in SingleStoreDialect.buildSelectQuery (dialect.ts:337) when iterating ordered selected fields: a referenced Column's underlying table is neither the FROM table nor present in the joins list. Drizzle cannot emit a valid SQL query that selects a column from a table that isn't in scope, so it aborts at SQL-build time with a message naming the offending table, column, and selection path.
Source
Thrown at drizzle-orm/src/singlestore-core/dialect.ts:337
&& getTableName(f.field.table)
!== (is(table, Subquery)
? table._.alias
/* : is(table, SingleStoreViewBase)
? table[ViewBaseConfig].name */
: is(table, SQL)
? undefined
: getTableName(table))
&& !((table) =>
joins?.some(
({ alias }) =>
alias
=== (table[Table.Symbol.IsAlias]
? getTableName(table)
: table[Table.Symbol.BaseName]),
))(f.field.table)
) {
const tableName = getTableName(f.field.table);
throw new Error(
`Your "${
f.path.join(
'->',
)
}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`,
);
}
}
const isSingleTable = !joins || joins.length === 0;
const withSql = this.buildWithCTE(withList);
const distinctSql = distinct ? sql` distinct` : undefined;
const selection = this.buildSelection(fieldsList, { isSingleTable });
const tableSql = (() => {View on GitHub (pinned to b7862528fd)
Solutions
- Add the missing join for the referenced table (e.g. .leftJoin(otherTable, eq(table.id, otherTable.fk))).
- If the table is already joined under an alias, select from the aliased instance (otherTableAlias.col), not the original table object.
- Remove the column from the select list if it is not actually needed.
Example fix
// before
await db.select({ id: users.id, petName: pets.name })
.from(users);
// after
await db.select({ id: users.id, petName: pets.name })
.from(users)
.leftJoin(pets, eq(users.id, pets.ownerId)); Defensive patterns
Strategy: validation
Validate before calling
import { getTableName } from 'drizzle-orm/table';
function collectUsedTables(fromTable, joins = []) {
const names = new Set([getTableName(fromTable)]);
for (const j of joins) if (j.alias) names.add(j.alias);
return names;
}
// before executing, verify every selected column's table is in the used set
function assertAllReferencedTablesJoined(selectFields, usedTables) {
for (const f of selectFields) {
if (f.path && f.field?.table) {
const t = getTableName(f.field.table);
if (!usedTables.has(t)) throw new Error(`Missing join for table ${t}`);
}
}
} Type guard
import { is, Column } from 'drizzle-orm';
function columnTableIsInQuery(col, fromTable, joins = []) {
const allowed = new Set([getTableName(fromTable), ...joins.map(j => j.alias).filter(Boolean)]);
return is(col, Column) && allowed.has(getTableName(col.table));
} Try / catch
try { await q; } catch (e) { if (/is not part of the query/.test(e.message)) { /* add the missing join */ } throw e; } Prevention
- Always pair a column selection from table T with a join on T.
- When aliasing via .as('x'), select columns from the aliased instance.
- Lint for orphaned column references when removing a join.
When it happens
Trigger: Calling db.select({ x: otherTable.col }).from(table) without a corresponding .leftJoin/.innerJoin on otherTable; referencing a joined table's column that was joined under a different alias than the one the column object carries; building a select with fieldsFlat referencing a subquery's outer column that isn't aliased to a joined table.
Common situations: Refactoring a query and deleting a join but forgetting to remove the now-orphaned column from the select list; aliasing a table with `.as('alias')` but selecting columns from the original (un-aliased) table object; copying a column reference from a different query's scope.
Related errors
- Your "${f.path.join('->')}" field references a column "${tab
- Your "${f.path.join('->')}" field references a column "${tab
- No fields selected for table "${tableConfig.tsName}" ("${tab
- Your "${f.path.join('->')}" field references a column "${tab
- Cannot execute a query on a query builder. Please use a data
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/5e9e5620e1987226.json.
Report an issue: GitHub.