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 while building a SQLite SELECT (dialect.ts:381) when a field in the selection list references a column belonging to a table that is neither the FROM table nor present in the joins list. Drizzle walks each selected field and checks the field's source table against the query's tables and join aliases; a miss means the SQL would reference an unjoined table, so it aborts.
Source
Thrown at drizzle-orm/src/sqlite-core/dialect.ts:381
&& getTableName(f.field.table)
!== (is(table, Subquery)
? table._.alias
: is(table, SQLiteViewBase)
? 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 = this.buildFromTable(table);View on GitHub (pinned to b7862528fd)
Solutions
- Add the missing .leftJoin(...) / .innerJoin(...) for the table that owns the column.
- When aliasing, reference the alias consistently in both the join and the selection.
- If the column belongs to the base table, ensure you did not accidentally pass a different table's column object.
Example fix
// before
db.select({ name: users.name, title: posts.title })
.from(users); // posts never joined -> throws
// after
db.select({ name: users.name, title: posts.title })
.from(users)
.leftJoin(posts, eq(posts.authorId, users.id)); Defensive patterns
Strategy: validation
Validate before calling
function assertTablesJoined(selectedTables: Set<string>, fromTable: string, joinAliases: string[]) {
const available = new Set([fromTable, ...joinAliases]);
for (const t of selectedTables) {
if (!available.has(t)) throw new Error(`Table ${t} referenced but not in FROM/joins`);
}
} Prevention
- Keep selected fields and joins in the same builder function so they stay in sync.
- When aliasing a table, use the alias object consistently in the selection.
- After dropping a join, grep for columns of that table in the selection.
When it happens
Trigger: Selecting a column from table B in a query that only .from(tableA) without joining B; referencing an aliased table whose alias does not match what was registered in the join; selecting fields from a subquery alias that was not added. Common with nested selections or when copy-pasting a field into a different query.
Common situations: Refactoring a query and dropping a join while keeping the column reference; aliasing a table on join (alias: 't') but referencing the original table name in the select; building queries dynamically from a shared field map.
Related errors
- Your "${f.path.join('->')}" field references a column "${tab
- Your "${f.path.join('->')}" field references a column "${tab
- Your "${f.path.join('->')}" field references a column "${tab
- Alias "${tableName}" is already used in this query
- 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/b40d2537b9b19181.json.
Report an issue: GitHub.