Home > other >  Auto increment from a custom id in sequelize with feathers-js not working
Auto increment from a custom id in sequelize with feathers-js not working

Time:06-25

I am trying to create a table that autoincrements starting from 1000.

Following this example, here's my code:

const Sequelize = require("sequelize");
const DataTypes = Sequelize.DataTypes;

module.exports = function (app) {
  const sequelizeClient = app.get("sequelizeClient");
  const users = sequelizeClient.define(
    "users",
    {
      first: {
        type: DataTypes.STRING,
        defaultValue: "User",
        //allowNull: true,
      },

    },
    {
      initialAutoIncrement: 1000,
      hooks: {
        beforeCount(options) {
          options.raw = true;
        },
      },
    }
  );

  // eslint-disable-next-line no-unused-vars
  users.associate = function (model) {
    // Define associations here
  };

  return users;
};

Where do I correctly place the initialAutoIncrement: 1000, option as this does not work?

CodePudding user response:

You have included both mySql and postgres in the tags for your post, so I'm not sure which dialect you are actually using.

If you are using postgres, the initialAutoIncrement option will not work. It's for mySql only.

https://sequelize.org/api/v7/interfaces/modeloptions#initialAutoIncrement

  • Related