【问题标题】:How to set a initial value in sequelize model?如何在续集模型中设置初始值?
【发布时间】:2021-09-12 05:33:49
【问题描述】:

我需要我的 id 不是从 1 开始。我尝试使用 initialAutoIncrement 但不起作用。

我的 id 应该从 1000 开始,并加一。

id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },

    initialAutoIncrement: 1000,
    timestamps: false
  }

【问题讨论】:

    标签: javascript node.js postgresql sequelize.js


    【解决方案1】:

    这应该可以工作

    async function myTest() {
        await sequelize.queryInterface.createTable('User', {
            id: {
                type: DataTypes.INTEGER,
                autoIncrement: true,
                primaryKey: true
            },
        }, {
            initialAutoIncrement: 1000
        });
    }
    

    【讨论】:

    • 谢谢!我试试看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    • 2019-09-28
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多