我正在做一个Express项目,并使用Sequelize作为我的ORM,我定义了以下Sequelize模型:
Field.init({
type: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
}
}, {
sequelize,
underscored: true,
tableName: "field",
});
假设现在我想限制type列的字符量,并创建如下所示的迁移(async up
是这里的焦点):
'use strict';
const { Transaction } = require('sequelize');
module.exports = {
async up(queryInterface, Sequelize) {
return queryInterface.sequelize.transaction({
isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE,
}, async t => {
await queryInterface.changeColumn('field', 'type', {
type: Sequelize.STRING(400),
allowNull: false,
},
{ transaction: t },
);
});
},
async down(queryInterface, Sequelize) {
return queryInterface.sequelize.transaction({
isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE,
}, async t => {
await queryInterface.changeColumn('field', 'type', {
type: Sequelize.STRING,
allowNull: false,
},
{ transaction: t },
);
});
}
};
unique
和allowNull
约束是否会保留在列中?或者这些会被删除,因为在迁移中我只列出了列的新类型?
1条答案
按热度按时间6qqygrtg1#