2017-07-30 12 views

回答

5

如果您使用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) 
}); 

參考文獻:

相關問題