versioned_docs/version-6.x.x/other-topics/upgrade.md
Sequelize v6 is the next major release after v5. Below is a list of breaking changes to help you upgrade.
Sequelize v6 will only support Node 10 and up #10821.
You should now use cls-hooked package for CLS support.
const cls = require('cls-hooked');
const namespace = cls.createNamespace('....');
const Sequelize = require('sequelize');
Sequelize.useCLS(namespace);
We have updated our minimum supported database engine versions. Using older database engine will show SEQUELIZE0006 deprecation warning. Please check the releases page for the version table.
Sequelize.Promise is no longer available.sequelize.import method has been removed. CLI users should update to sequelize-cli@6.options.returningOption returning: true will no longer return attributes that are not defined in the model. Old behavior can be achieved by using returning: ['*'] instead.
Model.changed()Sequelize does not detect deep mutations. To avoid problems with save, you should treat each attribute as immutable and only assign new values.
Example with a deep mutation of an attribute:
const instance = await MyModel.findOne();
// Sequelize will not detect this change
instance.jsonField.jsonProperty = 12345;
console.log(instance.changed()); // false
// You can workaround this by telling Sequelize the property changed:
instance.changed('jsonField', true);
console.log(instance.changed()); // true
Example if you treat each attribute as immutable:
const instance = await MyModel.findOne();
// Sequelize will detect this change
instance.jsonField = {
...instance.jsonField,
jsonProperty: 12345,
};
console.log(instance.changed()); // true
Model.bulkCreate()This method now throws Sequelize.AggregateError instead of Bluebird.AggregateError. All errors are now exposed as errors key.
Model.upsert()Native upsert is now supported for all dialects.
const [instance, created] = await MyModel.upsert({});
Signature for this method has been changed to Promise<Model,boolean | null>. First index contains upserted instance, second index contains a boolean (or null) indicating if record was created or updated. For SQLite/Postgres, created value will always be null.
<ins>Note for Postgres users:</ins> If upsert payload contains PK field, then PK will be used as the conflict target. Otherwise first unique constraint will be selected as the conflict key.
addConstraintThis method now only takes 2 parameters, tableName and options. Previously the second parameter could be a list of column names to apply the constraint to, this list must now be passed as options.fields property.
queryInterface.addIndex #11844plain option in sequelize.query #11596comparator arg of Sequelize.where #11843hooks to CreateOptions #11736options.storage #11853idle_in_transaction_session_timeout connection option #11775