如何设置sequelizejs以使用版本列?

Max*_*Max 6 postgresql sequelize.js

如何设置 Sequelize 以使用自动增量版本号?

根据文档,我需要的只是设置 version: true: http://docs.sequelizejs.com/manual/tutorial/models-definition.html#configuration

第一次尝试:

import Sequelize from "sequelize";

export const sequelize = new Sequelize('my_connection', 'fake-user-name', 'fake-password', {
  host: 'localhost',
  dialect: 'postgres'
});

export const User = sequelize.define('user', {
  id: {type: Sequelize.STRING, primaryKey: true},
  name: {type: Sequelize.STRING, allowNull: false}
}, {
  underscored: true,
  tableName: 'r_users',
  version: true // <- here
});
Run Code Online (Sandbox Code Playgroud)

结果:没有创建版本列。

第二次尝试:

import Sequelize from "sequelize";

export const sequelize = new Sequelize('my_connection', 'fake-user-name', 'fake-password', {
  host: 'localhost',
  dialect: 'postgres'
});

export const User = sequelize.define('user', {
  id: {type: Sequelize.STRING, primaryKey: true},
  name: {type: Sequelize.STRING, allowNull: false},
  version: {  // <- here as well
    type: Sequelize.INTEGER,
    allowNull: false,
    defaultValue: 0
  }
}, {
  underscored: true,
  tableName: 'r_users',
  version: true
});
Run Code Online (Sandbox Code Playgroud)

结果:版本列已创建,但在更新记录时它不会自动递增(我希望下面会递增版本):

User.find({where: {id: 1}}).then(item => {
  item.name = "Bob";
  item.save();
});
Run Code Online (Sandbox Code Playgroud)

笔记:

我使用的是 postgres 9.6,我使用的库如下:

  • “续集”:“^3.30.4”
  • "pg": "^6.2.3",
  • "pg-hstore": "^2.3.2",

问题:

谁能帮我指出我做错了什么?

提前致谢。