{"id":"68ca41fa539c3d75","repo":"typeorm/typeorm","slug":"column-columnorname-was-not-found-in-table","errorCode":null,"errorMessage":"Column \"${columnOrName}\" was not found in table \"${table.name}\"","messagePattern":"Column \"(.+?)\" was not found in table \"(.+?)\"","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"src/driver/aurora-mysql/AuroraMysqlQueryRunner.ts","lineNumber":1318,"sourceCode":"     *\n     * @param tableOrName\n     * @param columnOrName\n     * @param ifExists\n     */\n    async dropColumn(\n        tableOrName: Table | string,\n        columnOrName: TableColumn | string,\n        ifExists?: boolean,\n    ): Promise<void> {\n        const table = InstanceChecker.isTable(tableOrName)\n            ? tableOrName\n            : await this.getCachedTable(tableOrName)\n        const column = InstanceChecker.isTableColumn(columnOrName)\n            ? columnOrName\n            : table.findColumnByName(columnOrName)\n        if (!column) {\n            if (ifExists) return\n            throw new TypeORMError(\n                `Column \"${columnOrName}\" was not found in table \"${table.name}\"`,\n            )\n        }\n\n        const clonedTable = table.clone()\n        const upQueries: Query[] = []\n        const downQueries: Query[] = []\n\n        // drop primary key constraint\n        if (column.isPrimary) {\n            // if table have generated column, we must drop AUTO_INCREMENT before changing primary constraints.\n            const generatedColumn = clonedTable.columns.find(\n                (column) =>\n                    column.isGenerated &&\n                    column.generationStrategy === \"increment\",\n            )\n            if (generatedColumn) {\n                const nonGeneratedColumn = generatedColumn.clone()","sourceCodeStart":1300,"sourceCodeEnd":1336,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/driver/aurora-mysql/AuroraMysqlQueryRunner.ts#L1300-L1336","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait queryRunner.dropColumn('users', 'legacy_field') // throws if absent\n\n// after\nawait queryRunner.dropColumn('users', 'legacy_field', true) // no-op if absent","handlingStrategy":"validation","validationCode":"// Pass ifExists so a missing column is a no-op\nawait queryRunner.dropColumn(table, columnName, true)\n\n// Or pre-check explicitly\nconst t = await queryRunner.getTable(typeof table === 'string' ? table : table.name)\nif (t?.findColumnByName(typeof column === 'string' ? column : column.name)) {\n  await queryRunner.dropColumn(table, column)\n}","typeGuard":"function columnExists(table: Table | undefined, name: string): table is Table {\n  return !!table && !!table.findColumnByName(name)\n}\n\nif (columnExists(await queryRunner.getTable('users'), 'legacy_field')) {\n  await queryRunner.dropColumn('users', 'legacy_field')\n}","tryCatchPattern":"try {\n  await queryRunner.dropColumn(table, columnName)\n} catch (e) {\n  if (e instanceof TypeORMError && /was not found in table/i.test(e.message)) {\n    // column already gone; idempotent no-op\n  } else {\n    throw e\n  }\n}","preventionTips":["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"],"tags":["schema","ddl","column","migration","aurora-mysql","typescript","typeorm"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}