在sequalize PostgreSQL中,有什么方法可以编辑自动增量值?
我要编辑订单值,有什么方法可以编辑它?由于这是我尝试在pg admin中更新的自动递增属性,因此它不是查询update category set order = 22 where id = 2
。所以有人请指导我
迁移文件:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('category', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
media_id: {
type: Sequelize.INTEGER,
allowNull: false,
onDelete: 'CASCADE',
references: {
model: 'media',
key: 'id',
as: 'media_id'
}
},
order: {
allowNull: false,
autoIncrement: true,
type: Sequelize.INTEGER
},
category_name: Sequelize.TEXT,
created_at: {
allowNull: false,
type: Sequelize.DATE
},
updated_at: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('category');
}
};
模型文件
'use strict';
module.exports = (sequelize, DataTypes) => {
const Category = sequelize.define('Category', {
media_id: {
type: DataTypes.INTEGER,
allowNull: false,
onDelete: 'CASCADE',
references: {
model: 'media',
key: 'id',
as: 'media_id'
}
},
order: {
type: DataTypes.INTEGER
},
latin_chars: DataTypes.STRING
}, {
underscored: true,
freezeTableName: true,
tableName: 'category'
});
答案 0 :(得分:0)
我认为这是一个序列,您可以在pgAdmin中找到该序列,然后操纵该序列。数据库是跟踪序列中您所处位置而不是序列化的对象