简体   繁体   English

not null 违例:model.field cannot be null

[英]not null violation: model.field cannot be null

I have sequelize models and everything is synced up with the db:我有续集模型,所有内容都与数据库同步:

supplier:供应商:

 class Suppliers extends Model {} Suppliers.init({ id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true }, name: { type: DataTypes.STRING, allowNull: false }, firstName: { type: DataTypes.STRING, allowNull: false }, email: { type: DataTypes.STRING, allowNull: false }, password: { type: DataTypes.STRING, allowNull: false }, phone: { type: DataTypes.STRING, allowNull: false }, lastName: { type: DataTypes.STRING // allowNull defaults to true } }, { sequelize, modelName: 'supplier' }); console.log({suppliers:Suppliers === sequelize.models.Suppliers}); export{Suppliers}

and I am making this query to add records to the suppliers table:我正在进行此查询以将记录添加到供应商表中:

 async function create(user) { init() user.dateCreated = new Date().toISOString(); user.dateUpdated = new Date().toISOString(); let nwUser; try { console.log({values: {name:user.name, password:user.hash, email:user.email, phone: user.phone, firstName: user.firstName, lastName: user.lastName}}) nwUser = await Suppliers.create({values: {name:user.name, password:user.hash, email:user.email, phone: user.phone, firstName: user.firstName, lastName: user.lastName}}).then(rs=>{ console.log({rscreate:rs}) return rs }).catch(err=>console.log(err)); return nwUser } catch (error) { console.log(error); }

but I get the above mentioned error for all the values I pass to the query.但是对于我传递给查询的所有值,我都得到了上述错误。 but as you see when I console.log them they are there.但正如您看到的,当我控制台记录它们时,它们就在那里。

You shouldn't wrap all fields into values prop.您不应该将所有字段都包装到values道具中。 Just pass them directly:直接传递它们:

nwUser = await Suppliers.create({name:user.name, password:user.hash, email:user.email, phone: user.phone, firstName: user.firstName, lastName: user.lastName})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 栏位不能为NULL - Field cannot be NULL {"message": "notNull Violation: users.firstName cannot be null,\nnotNull Violation: users.lastName cannot be null} 我面临的错误 - {"message": "notNull Violation: users.firstName cannot be null,\nnotNull Violation: users.lastName can not be null} error I am facing 运行测试时出现“不变违规:本机模块不能为空”。 - Getting ''Invariant Violation: Native module cannot be null.'' when I run the test 在输入字段中使用 ng-model 的 Angular 为空 - Angular using ng-model in input field get null 开玩笑,反应本机和异步存储:不变违规:本机模块不能是 null - Jest, React native and async-storage : Invariant Violation: Native module cannot be null 不变违规:Native Module 不能是 Null。 错误仅出现在 iOS - Invariant Violation: Native Module cannot be Null. Error only showing up on iOS 错误:无法在 Img 字段中设置 null 的属性“src” - Error: Cannot set property 'src' of null at Img field 无法为 GraphQL 查询中的不可空字段返回 null - Cannot return null for non-nullable field in a GraphQL query 将模型排序为空/空 - Sequelize model to null / empty mongodb字段永远不会为空? - mongodb field is never null?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM