I can't find an answer. I want to add a new column to an existing table that should be an auto incrementing integer, starting with the value of 1000.
My migration file is for now simple and obvious:
'use strict';
module.exports = {
up: async (queryInterface, Sequelize, _, db) => {
const { DataTypes } = Sequelize;
const { sequelize } = db;
await queryInterface.addColumn('class', 'id', {
allowNull: false,
type: DataTypes.INTEGER,
unique: true,
defaultValue: 1000,
autoIncrement: true,
initialAutoIncrement: 1000
});
},
down: {...}
};
So this adds the column to the table class, but it sets the initial value to 1 instead of 1000.
I know it is already present in Sequelize. There is an option called initialAutoIncrement. This sets the initial AUTO_INCREMENT value for the table in MySQL. I even tried that in the model, but without any luck.
module.exports = (sequelize, DataTypes) => {
const Class = sequelize.define(
'User',
{
id: {
type: DataTypes.BIGINT(20),
primaryKey: true,
autoIncrement: true,
},
name: {
type: DataTypes.STRING(500),
allowNull: false,
},
},
{
initialAutoIncrement: 1000,
}
);
return Class;
};
Is there a solution for this?