I'm trying to update the id value of an existing instance using Sequelize but it is not being persisted to the DB
// model definition
var User = sequelize.define('users', {
id: {
type: DataTypes.STRING,
unique: true,
primaryKey: true,
field: 'id'
}
)};
// usage
User.findById(oldId).then(function(user) {
user.id = 'new value';
user.save(); // Id remains the same in DB
});
I'm using sequelize 3.14.0 with node and a PostgreSQL database.
As others have hinted in the comments, sequelize won't let you update the primary key, see https://github.com/sequelize/sequelize/blob/f482790b85ef2336bb97893c0eaa127d9d6bbc77/lib/instance.js#L334-L336
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With