{"id":"7ed34d43fd040c96","repo":"drizzle-team/drizzle-orm","slug":"db-or-schema-or-tablename-is-undefined","errorCode":null,"errorMessage":"db or schema or tableName is undefined.","messagePattern":"db or schema or tableName is undefined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-seed/src/services/SeedService.ts","lineNumber":1436,"sourceCode":"\t\tif (is(db, PgDatabase<any>)) {\n\t\t\t// @ts-ignore\n\t\t\tmaxParametersNumber = db.constructor[entityKind] === 'PgliteDatabase'\n\t\t\t\t? this.postgresPgLiteMaxParametersNumber\n\t\t\t\t: this.postgresMaxParametersNumber;\n\t\t} else if (is(db, MySqlDatabase<any, any>)) {\n\t\t\tmaxParametersNumber = this.mysqlMaxParametersNumber;\n\t\t} else {\n\t\t\t// is(db, BaseSQLiteDatabase<any, any>)\n\t\t\tmaxParametersNumber = this.sqliteMaxParametersNumber;\n\t\t}\n\t\tconst maxBatchSize = Math.floor(maxParametersNumber / columnsNumber);\n\t\tbatchSize = batchSize > maxBatchSize ? maxBatchSize : batchSize;\n\n\t\tif (\n\t\t\t(insertDataInDb === true || updateDataInDb === true)\n\t\t\t&& (db === undefined || schema === undefined || tableName === undefined)\n\t\t) {\n\t\t\tthrow new Error('db or schema or tableName is undefined.');\n\t\t}\n\n\t\tlet row: { [columnName: string]: string | number | boolean },\n\t\t\tgeneratedValue,\n\t\t\ti: number;\n\n\t\tfor (i = 0; i < count; i++) {\n\t\t\trow = {};\n\t\t\tgeneratedValues.push(row);\n\n\t\t\tfor (const columnName of Object.keys(columnsGenerators)) {\n\t\t\t\t// generatedValue = columnsGenerators[columnName].next().value as\n\t\t\t\t//   | string\n\t\t\t\t//   | number\n\t\t\t\t//   | boolean;\n\t\t\t\tgeneratedValue = columnsGenerators[columnName]!.generate({ i }) as\n\t\t\t\t\t| string\n\t\t\t\t\t| number","sourceCodeStart":1418,"sourceCodeEnd":1454,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-seed/src/services/SeedService.ts#L1418-L1454","documentation":"generateColumnsValuesByGenerators accepts optional db, schema, and tableName parameters because it can run in a 'generate-only' mode (returning values without writing to the DB). When insertDataInDb or updateDataInDb is true, all three are required to perform the write. If any is undefined under those conditions, it throws.","triggerScenarios":"Calling the seeder with insertDataInDb: true (the default) or updateDataInDb: true but not passing a db connection, a schema object, or a tableName; or a programmatic caller of generateColumnsValuesByGenerators that forgot to forward one of the three.","commonSituations":"Using drizzle-seed programmatically (not via the top-level seed() wrapper) and omitting the db or schema argument; conditionally passing db only in some code paths.","solutions":["Ensure db, schema, and tableName are all passed when insertDataInDb/updateDataInDb is true.","If you only want generated values without DB writes, explicitly set insertDataInDb: false and updateDataInDb: false.","When using the high-level seed() function, make sure both the db instance and the schema object are provided."],"exampleFix":"// before — missing db/schema when inserting\nawait seedService.generateColumnsValuesByGenerators({\n  tableGenerators, tableName: 'users', count: 10, // db & schema omitted\n});\n// after — provide all three for DB writes\nawait seedService.generateColumnsValuesByGenerators({\n  tableGenerators, db, schema, tableName: 'users', count: 10,\n});","handlingStrategy":"validation","validationCode":"function validateSeedWriteParams(opts: {\n  insertDataInDb?: boolean;\n  updateDataInDb?: boolean;\n  db?: unknown;\n  schema?: unknown;\n  tableName?: string;\n}): string | null {\n  const willWrite = opts.insertDataInDb !== false || opts.updateDataInDb === true;\n  if (willWrite && (opts.db === undefined || opts.schema === undefined || opts.tableName === undefined)) {\n    return 'db, schema, and tableName are all required when inserting or updating data in the DB.';\n  }\n  return null;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass db and schema to the top-level seed() function.","When calling generateColumnsValuesByGenerators directly, forward all three params for write mode.","Set insertDataInDb: false explicitly if you only need generated values."],"tags":["missing-argument","db-connection","insert","config"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}