{"id":"c2e56689d64540b0","repo":"drizzle-team/drizzle-orm","slug":"you-cannot-use-both-where-and-targetwhere-set-c2e566","errorCode":null,"errorMessage":"You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.","messagePattern":"You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/sqlite-core/query-builders/insert.ts","lineNumber":350,"sourceCode":"\t *   .values({ id: 1, brand: 'BMW' })\n\t *   .onConflictDoUpdate({\n\t *     target: cars.id,\n\t *     set: { brand: 'Porsche' }\n\t *   });\n\t *\n\t * // Upsert with 'where' clause\n\t * await db.insert(cars)\n\t *   .values({ id: 1, brand: 'BMW' })\n\t *   .onConflictDoUpdate({\n\t *     target: cars.id,\n\t *     set: { brand: 'newBMW' },\n\t *     where: sql`${cars.createdAt} > '2023-01-01'::date`,\n\t *   });\n\t * ```\n\t */\n\tonConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {\n\t\tif (config.where && (config.targetWhere || config.setWhere)) {\n\t\t\tthrow new Error(\n\t\t\t\t'You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.',\n\t\t\t);\n\t\t}\n\n\t\tif (!this.config.onConflict) this.config.onConflict = [];\n\n\t\tconst whereSql = config.where ? sql` where ${config.where}` : undefined;\n\t\tconst targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;\n\t\tconst setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;\n\t\tconst targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;\n\t\tconst setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));\n\t\tthis.config.onConflict.push(\n\t\t\tsql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,\n\t\t);\n\t\treturn this;\n\t}\n\n\t/** @internal */","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/sqlite-core/query-builders/insert.ts#L332-L368","documentation":"Thrown by SQLiteInsertBase.onConflictDoUpdate (insert.ts:350) when the config object supplies both the deprecated 'where' key and at least one of the newer 'targetWhere'/'setWhere' keys. Drizzle migrated the ON CONFLICT WHERE clause into two distinct filters (targetWhere for the conflict target, setWhere for the UPDATE) and made 'where' deprecated; mixing them is ambiguous and rejected.","triggerScenarios":"Calling .onConflictDoUpdate({ target, set, where, targetWhere }) or { where, setWhere } — any combination that includes where alongside targetWhere or setWhere.","commonSituations":"Upgrading drizzle and keeping old 'where' while adding the new keys; copy-pasting an example that used the old API next to new-style config; partial migration of upsert calls.","solutions":["Remove the deprecated 'where' key and use 'targetWhere' (filter the conflict target) and/or 'setWhere' (filter the update) instead.","If you only need one WHERE clause, pick the semantically correct new key and drop 'where'.","Grep the codebase for onConflictDoUpdate and remove every lingering 'where' after a version upgrade."],"exampleFix":"// before\n.onConflictDoUpdate({\n  target: users.id,\n  set: { name: 'x' },\n  where: sql`...`,       // deprecated\n  targetWhere: sql`...`, // new — combining throws\n});\n\n// after\n.onConflictDoUpdate({\n  target: users.id,\n  set: { name: 'x' },\n  targetWhere: sql`...`, // filter the conflict target\n  setWhere: sql`...`,    // filter the update\n});","handlingStrategy":"validation","validationCode":"function onConflictConfig(cfg) {\n  if (cfg.where && (cfg.targetWhere || cfg.setWhere)) {\n    throw new Error('Remove deprecated \"where\"; use targetWhere/setWhere');\n  }\n  return cfg;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After upgrading drizzle, grep for onConflictDoUpdate and delete every 'where' key.","Learn the targetWhere vs setWhere semantics (conflict-target filter vs update filter).","Add an ESLint/TS rule or wrapper that rejects the deprecated 'where' option."],"tags":["insert","upsert","on-conflict","migration","deprecated"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}