0
比方說,我想要在續集中製作首字母字段,在貓鼬中,我只需要說:在該字段上是true,但在Sequelize中我該如何做?如何在Sequelize中創建一個字段?
比方說,我想要在續集中製作首字母字段,在貓鼬中,我只需要說:在該字段上是true,但在Sequelize中我該如何做?如何在Sequelize中創建一個字段?
如果您使用Sequelize,相當於貓鼬required: true
只是allowNull: false
。你會寫幾行內容:
const YourTable = sequelize.define('your_table', {
firstname: {
type: Sequelize.STRING,
// This will require the firstname be present
allowNull: false,
// If you want to also have a length restriction, add the next line
len: [2,50], // only allow values with length between 2 and 50
// That is 'Al' will be accepted and so will 'Rigoberto Fernando Luis María'.
// But '' or 'J' won't be good enough
// If you use sequelize transforms, this will remove spaces on both ends
// of the string also
trim: true,
},
// All the other fields (columns)
});
參考文獻: