{"id":"84346085e75811ef","repo":"sequelize/sequelize","slug":"upserts-are-not-supported-by-the-this-dialect-na","errorCode":null,"errorMessage":"Upserts are not supported by the ${this.dialect.name} dialect.","messagePattern":"Upserts are not supported by the (.+?) dialect\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/abstract-dialect/query-interface.js","lineNumber":399,"sourceCode":"\n  /**\n   * Upsert\n   *\n   * @param {string} tableName    table to upsert on\n   * @param {object} insertValues values to be inserted, mapped to field name\n   * @param {object} updateValues values to be updated, mapped to field name\n   * @param {object} where        where conditions, which can be used for UPDATE part when INSERT fails\n   * @param {object} options      query options\n   *\n   * @returns {Promise<boolean,?number>} Resolves an array with <created, primaryKey>\n   */\n  // Note: \"where\" is only used by DB2 and MSSQL. This is because these dialects do not propose any \"ON CONFLICT UPDATE\" mechanisms\n  // The UPSERT pattern in SQL server requires providing a WHERE clause\n  // TODO: the user should be able to configure the WHERE clause for upsert instead of the current default which\n  //  is using the primary keys.\n  async upsert(tableName, insertValues, updateValues, where, options) {\n    if (!this.dialect.supports.upserts) {\n      throw new Error(`Upserts are not supported by the ${this.dialect.name} dialect.`);\n    }\n\n    if (options?.bind) {\n      assertNoReservedBind(options.bind);\n    }\n\n    options = { ...options };\n\n    const model = options.model;\n    const modelDefinition = model.modelDefinition;\n\n    options.type = QueryTypes.UPSERT;\n    options.updateOnDuplicate = Object.keys(updateValues);\n    options.upsertKeys = options.conflictFields || [];\n\n    if (options.upsertKeys.length === 0) {\n      const primaryKeys = Array.from(\n        map(","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/core/src/abstract-dialect/query-interface.js#L381-L417","documentation":"Thrown at the top of QueryInterface.upsert (query-interface.js:398) when the active dialect reports supports.upserts as false. Sequelize cannot emit a valid ON CONFLICT / MERGE statement for dialects that lack native upsert support, so it aborts before building any SQL rather than producing a silent no-op or incorrect query.","triggerScenarios":"Calling Model.upsert() or queryInterface.upsert() against a dialect whose supports.upserts flag is false; running the same code that worked on Postgres against a dialect with no upsert capability.","commonSituations":"Switching database dialects during a migration or multi-DB product; using a community/older dialect adapter; deploying code originally written for Postgres/MSSQL to a dialect that lacks ON CONFLICT.","solutions":["Check sequelize.dialect.supports.upserts before calling upsert and branch accordingly.","Replace upsert with a manual findOne + (create | update) sequence for unsupported dialects.","Switch to a dialect adapter that supports upserts if the workload requires it."],"exampleFix":"// before\nawait User.upsert({ id: 1, name: 'Jane' });\n\n// after (guard for dialects without upsert support)\nif (sequelize.dialect.supports.upserts) {\n  await User.upsert({ id: 1, name: 'Jane' });\n} else {\n  const [user, created] = await User.findOrCreate({\n    where: { id: 1 },\n    defaults: { name: 'Jane' },\n  });\n  if (!created) await user.update({ name: 'Jane' });\n}","handlingStrategy":"type-guard","validationCode":"function dialectSupportsUpsert(sequelize) {\n  return Boolean(sequelize.dialect.supports.upserts);\n}","typeGuard":"function supportsUpserts(sequelize): sequelize is { dialect: { supports: { upserts: true } } } {\n  return Boolean((sequelize.dialect.supports as any).upserts);\n}","tryCatchPattern":"try {\n  await Model.upsert(record);\n} catch (e) {\n  if (/Upserts are not supported/.test(e.message)) {\n    // fall back to findOrCreate + update\n  } else {\n    throw e;\n  }\n}","preventionTips":["Check sequelize.dialect.supports.upserts once at startup and branch your write path.","Keep a fallback (findOrCreate + update) for dialects without upsert.","Document which dialects your app supports upsert on."],"tags":["query-interface","upsert","dialect","feature-support"],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}