{"record":{"id":"c8855ad17a6780c4","repo":"balderdashy/sails","slug":"cannot-change-primary-key-via-update-blueprint-ig","errorCode":null,"errorMessage":"Cannot change primary key via update blueprint; ignoring value sent for `${Model.primaryKey}`","messagePattern":"Cannot change primary key via update blueprint; ignoring value sent for `(.+?)`","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/hooks/blueprints/parse-blueprint-options.js","lineNumber":316,"sourceCode":"\n      // Note that we do NOT set `fetch: true`, because if we do so, some versions\n      // of Waterline complain that `fetch` need not be included with .updateOne().\n      // (Now that we take advantage of .updateOne() in blueprints, this is a thing.)\n      queryOptions.meta = {};\n\n      //  ┌─┐┌─┐┬─┐┌─┐┌─┐  ┬  ┬┌─┐┬  ┬ ┬┌─┐┌─┐\n      //  ├─┘├─┤├┬┘└─┐├┤   └┐┌┘├─┤│  │ │├┤ └─┐\n      //  ┴  ┴ ┴┴└─└─┘└─┘   └┘ ┴ ┴┴─┘└─┘└─┘└─┘\n\n      queryOptions.valuesToSet = (function getValuesToSet(){\n\n        // Use all of the request params as values for the new record, _except_ `id`.\n        var values = _.omit(req.allParams(), 'id');\n\n        // No matter what, don't allow changing the PK via the update blueprint\n        // (you should just drop and re-add the record if that's what you really want)\n        if (typeof values[Model.primaryKey] !== 'undefined' && values[Model.primaryKey] !== queryOptions.criteria.where[Model.primaryKey]) {\n          req._sails.log.warn('Cannot change primary key via update blueprint; ignoring value sent for `' + Model.primaryKey + '`');\n        }\n        // Make sure the primary key is unchanged\n        values[Model.primaryKey] = queryOptions.criteria.where[Model.primaryKey];\n\n        return values;\n\n      })();\n\n\n      break;\n\n    //  ██████╗ ███████╗███████╗████████╗██████╗  ██████╗ ██╗   ██╗\n    //  ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗╚██╗ ██╔╝\n    //  ██║  ██║█████╗  ███████╗   ██║   ██████╔╝██║   ██║ ╚████╔╝\n    //  ██║  ██║██╔══╝  ╚════██║   ██║   ██╔══██╗██║   ██║  ╚██╔╝\n    //  ██████╔╝███████╗███████║   ██║   ██║  ██║╚██████╔╝   ██║\n    //  ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚═╝  ╚═╝ ╚═════╝    ╚═╝\n    case 'destroy':","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/balderdashy/sails/blob/7b76422cc27823df033572bdda5c4910a68b697f/lib/hooks/blueprints/parse-blueprint-options.js#L298-L334","documentation":"In the update blueprint's parameter parsing (parse-blueprint-options.js), if the request params include a new value for the model's primary key that differs from the PK in the request's where criteria, Sails logs this warning and forcibly keeps the original PK. Changing a record's primary key via the update blueprint is not allowed — you must drop and re-create the record.","triggerScenarios":"PUT/PATCH to a blueprint update route with a body that includes a field named after the primary key (usually 'id') whose value differs from the record's actual id in queryOptions.criteria.where.","commonSituations":"Client forms send the whole record including the id field while the route embeds a different id, generic UI components that serialize all fields on update, or bulk-edit frontends that let users edit the id column.","solutions":["Remove the primary key field from the update payload; send only mutable attributes.","Ensure the id in the URL/body matches the record you intend to update.","If PK changes are truly required, drop and re-add the record (custom action or direct database operation)."],"exampleFix":"// before\nawait fetch('/api/users/7', {method:'PUT', body: JSON.stringify({id: 9, name: 'x'})});\n// after\nawait fetch('/api/users/7', {method:'PUT', body: JSON.stringify({name: 'x'})});","handlingStrategy":"validation","validationCode":"const params = req.allParams();\nif (params.id !== undefined && req.param('id') !== undefined && String(params[Model.primaryKey]) !== String(req.options.values?.where?.[Model.primaryKey] ?? req.params[Model.primaryKey])) {\n  delete params[Model.primaryKey]; // strip PK before sending update\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never include the primary key in update payloads; whitelist mutable attributes.","Strip immutable fields server-side before delegating to the update blueprint.","Treat PKs as immutable — drop-and-recreate when a PK change is genuinely needed."],"tags":["blueprints","update","primary-key","api"],"backgroundTag":"primary-key-immutable","analyzedSha":"7b76422cc27823df033572bdda5c4910a68b697f","analyzedAt":"2026-09-01T04:01:57.104Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}