{"id":"92ff232d58e35c3b","repo":"typeorm/typeorm","slug":"column-column-was-not-found-in-table-table","errorCode":null,"errorMessage":"Column \"${column}\" was not found in table \"${table.name}\"","messagePattern":"Column \"(.+?)\" was not found in table \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts","lineNumber":835,"sourceCode":"     */\n    async dropColumns(\n        tableOrName: Table | string,\n        columns: TableColumn[] | string[],\n        ifExists?: boolean,\n    ): Promise<void> {\n        const table = InstanceChecker.isTable(tableOrName)\n            ? tableOrName\n            : await this.getCachedTable(tableOrName)\n\n        // clone original table and remove column and its constraints from cloned table\n        const changedTable = table.clone()\n        columns.forEach((column: TableColumn | string) => {\n            const columnInstance = InstanceChecker.isTableColumn(column)\n                ? column\n                : table.findColumnByName(column)\n            if (!columnInstance) {\n                if (ifExists) return\n                throw new Error(\n                    `Column \"${column}\" was not found in table \"${table.name}\"`,\n                )\n            }\n\n            changedTable.removeColumn(columnInstance)\n            changedTable\n                .findColumnUniques(columnInstance)\n                .forEach((unique) =>\n                    changedTable.removeUniqueConstraint(unique),\n                )\n            changedTable\n                .findColumnIndices(columnInstance)\n                .forEach((index) => changedTable.removeIndex(index))\n            changedTable\n                .findColumnForeignKeys(columnInstance)\n                .forEach((fk) => changedTable.removeForeignKey(fk))\n        })\n","sourceCodeStart":817,"sourceCodeEnd":853,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts#L817-L853","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait queryRunner.dropColumns(\"user\", [\"a\", \"b\", \"c\"]);\n// after\nawait queryRunner.dropColumns(\"user\", [\"a\", \"b\", \"c\"], true);","handlingStrategy":"validation","validationCode":"const table = await queryRunner.getTable(tableName);\nconst existing = names.filter(n => table?.findColumnByName(n));\nif (existing.length) await queryRunner.dropColumns(table!, existing, true);","typeGuard":"const columnsExist = (table: Table | undefined, names: string[]) =>\n  names.filter(n => table?.findColumnByName(n));","tryCatchPattern":"try { await queryRunner.dropColumns(t, cols); }\ncatch (e) { if (e instanceof Error && /was not found/.test(e.message)) { /* skip */ } else throw e; }","preventionTips":["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."],"tags":["sqlite","schema","migration","typeorm"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}