typeorm/typeorm · error · Error
Column "${column}" was not found in table "${table.name}"
Error message
Column "${column}" was not found in table "${table.name}" What it means
Thrown by dropColumns() for each entry in the columns array that cannot be resolved. Functionally identical in meaning to the dropColumn error but emitted from the batch path. Note the source throws a plain `new Error(...)` here rather than TypeORMError — a minor inconsistency in the codebase, so callers catching by error class should catch broadly.
Source
Thrown at src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts:835
*/
async dropColumns(
tableOrName: Table | string,
columns: TableColumn[] | string[],
ifExists?: boolean,
): Promise<void> {
const table = InstanceChecker.isTable(tableOrName)
? tableOrName
: await this.getCachedTable(tableOrName)
// clone original table and remove column and its constraints from cloned table
const changedTable = table.clone()
columns.forEach((column: TableColumn | string) => {
const columnInstance = InstanceChecker.isTableColumn(column)
? column
: table.findColumnByName(column)
if (!columnInstance) {
if (ifExists) return
throw new Error(
`Column "${column}" was not found in table "${table.name}"`,
)
}
changedTable.removeColumn(columnInstance)
changedTable
.findColumnUniques(columnInstance)
.forEach((unique) =>
changedTable.removeUniqueConstraint(unique),
)
changedTable
.findColumnIndices(columnInstance)
.forEach((index) => changedTable.removeIndex(index))
changedTable
.findColumnForeignKeys(columnInstance)
.forEach((fk) => changedTable.removeForeignKey(fk))
})
View on GitHub (pinned to 04ff4daedc)
Solutions
- Pass ifExists=true as the third argument to dropColumns so missing entries are skipped.
- Pre-filter the list against table.columns before calling.
- Catch with `instanceof Error` (not TypeORMError) since this path throws a base Error.
- Reconnect/refresh schema cache and retry if the cache is suspected stale.
Example fix
// before
await queryRunner.dropColumns("user", ["a", "b", "c"]);
// after
await queryRunner.dropColumns("user", ["a", "b", "c"], true); Defensive patterns
Strategy: validation
Validate before calling
const table = await queryRunner.getTable(tableName); const existing = names.filter(n => table?.findColumnByName(n)); if (existing.length) await queryRunner.dropColumns(table!, existing, true);
Type guard
const columnsExist = (table: Table | undefined, names: string[]) => names.filter(n => table?.findColumnByName(n));
Try / catch
try { await queryRunner.dropColumns(t, cols); }
catch (e) { if (e instanceof Error && /was not found/.test(e.message)) { /* skip */ } else throw e; } Prevention
- Pre-filter the columns array against the cached table.
- Pass ifExists=true (3rd arg) to skip missing entries.
- Catch Error (not TypeORMError) — this path throws a base Error.
When it happens
Trigger: Calling queryRunner.dropColumns(table, [colA, colB]) where any element is a string absent from table.columns or a TableColumn instance not held by the table. The ifExists flag (third arg) applies to all entries uniformly.
Common situations: Batch-dropping columns in a migration where one was already removed; mismatch between migration code and current DB state; typo in one element of the array; passing mixed string/TableColumn instances with a stale reference.
Related errors
- Column "${columnOrName}" was not found in table "${table.nam
- Supplied unique constraint was not found in table ${table.na
- Supplied check constraint was not found in table ${table.nam
- Supplied foreign key was not found in table ${table.name}
- Supplied index ${indexOrName} was not found in table ${table
AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03).
Data as JSON: /data/errors/92ff232d58e35c3b.json.
Report an issue: GitHub.