typeorm/typeorm · error · TypeORMError
Column "${columnOrName}" was not found in table "${table.nam
Error message
Column "${columnOrName}" was not found in table "${table.name}" What it means
Thrown inside dropColumn() when the column is not found and the ifExists flag is not set. The method resolves columnOrName via InstanceChecker.isTableColumn or table.findColumnByName; a miss with ifExists falsy throws a TypeORMError. Passing ifExists=true makes a missing column a silent no-op instead.
Source
Thrown at src/driver/aurora-mysql/AuroraMysqlQueryRunner.ts:1318
*
* @param tableOrName
* @param columnOrName
* @param ifExists
*/
async dropColumn(
tableOrName: Table | string,
columnOrName: TableColumn | string,
ifExists?: boolean,
): Promise<void> {
const table = InstanceChecker.isTable(tableOrName)
? tableOrName
: await this.getCachedTable(tableOrName)
const column = InstanceChecker.isTableColumn(columnOrName)
? columnOrName
: table.findColumnByName(columnOrName)
if (!column) {
if (ifExists) return
throw new TypeORMError(
`Column "${columnOrName}" was not found in table "${table.name}"`,
)
}
const clonedTable = table.clone()
const upQueries: Query[] = []
const downQueries: Query[] = []
// drop primary key constraint
if (column.isPrimary) {
// if table have generated column, we must drop AUTO_INCREMENT before changing primary constraints.
const generatedColumn = clonedTable.columns.find(
(column) =>
column.isGenerated &&
column.generationStrategy === "increment",
)
if (generatedColumn) {
const nonGeneratedColumn = generatedColumn.clone()View on GitHub (pinned to 04ff4daedc)
Solutions
- Pass the ifExists flag: await queryRunner.dropColumn(table, 'colName', true) to make a missing column a no-op
- Pre-check with hasColumn or findColumnByName before dropping
- Make drop migrations idempotent by guarding with an existence check
- Ensure the table cache is current by calling getTable() first
Example fix
// before
await queryRunner.dropColumn('users', 'legacy_field') // throws if absent
// after
await queryRunner.dropColumn('users', 'legacy_field', true) // no-op if absent Defensive patterns
Strategy: validation
Validate before calling
// Pass ifExists so a missing column is a no-op
await queryRunner.dropColumn(table, columnName, true)
// Or pre-check explicitly
const t = await queryRunner.getTable(typeof table === 'string' ? table : table.name)
if (t?.findColumnByName(typeof column === 'string' ? column : column.name)) {
await queryRunner.dropColumn(table, column)
} Type guard
function columnExists(table: Table | undefined, name: string): table is Table {
return !!table && !!table.findColumnByName(name)
}
if (columnExists(await queryRunner.getTable('users'), 'legacy_field')) {
await queryRunner.dropColumn('users', 'legacy_field')
} Try / catch
try {
await queryRunner.dropColumn(table, columnName)
} catch (e) {
if (e instanceof TypeORMError && /was not found in table/i.test(e.message)) {
// column already gone; idempotent no-op
} else {
throw e
}
} Prevention
- Pass the third ifExists argument (true) to dropColumn for idempotent migrations
- Pre-check with hasColumn or findColumnByName before dropping
- Make drop migrations idempotent to support re-runs
- Refresh table metadata via getTable() before the drop
When it happens
Trigger: Calling dropColumn(table, 'colName') when the column doesn't exist (without the third ifExists argument); dropping a column already removed by a previous migration; running a drop migration against a DB at an older/newer state than expected.
Common situations: Idempotent migration re-runs where the column was already dropped; dev/test DBs at different migration versions; branching that drops the same column in two branches then merges; manual column drops leaving TypeORM's expectations stale.
Related errors
- Column "${oldTableColumnOrName}" was not found in the "${tab
- Column "${oldColumnOrName}" was not found in the "${table.na
- Schema create queries are not supported by MySql driver.
- Schema drop queries are not supported by MySql driver.
- MySql does not support unique constraints. Use unique index
AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03).
Data as JSON: /data/errors/68ca41fa539c3d75.json.
Report an issue: GitHub.