Something went wrong?
DimitarDechew opened this issue · 0 comments
DimitarDechew commented
So basically, I've just updated node-orm and something happened with the validations and the models. My problem is that I have beforeValidation function like this one:
var Device = db.define('device', {
name : { type : 'text', required : true },
brand : { type : 'text', required : true },
width : { type : 'number', required : true },
height : { type : 'number', required : true },
active : { type : 'boolean', required : true },
createdAt : { type : 'date', required : true}
},
{
hooks: {
beforeValidation: () => {
this.createdAt = new Date()
}
},
validations: {
name: [
db.enforce.unique({ ignoreCase : true }, 'Oops! There is a device with that name.'),
db.enforce.ranges.length(1, undefined, 'Device name should be atleast 1 character long.'),
db.enforce.ranges.length(32, undefined, 'Device name cannot be more than 32 characters long.')
]
}
})
And I'm getting this error:
New client connected to the server
Message received[object Object]
Unhandled rejection Error: ER_NO_DEFAULT_FOR_FIELD: Field 'createdAt' doesn't have a default value
at Query.Sequence._packetToError (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Query.ErrorPacket (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\sequences\Query.js:77:18)
at Protocol._parsePacket (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\Connection.js:103:28)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:597:20)
--------------------
at Protocol._enqueue (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\Protocol.js:145:48)
at PoolConnection.query (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\Connection.js:208:25)
at C:\Users\User\Desktop\qsell-project\node_modules\orm\lib\Drivers\DML\mysql.js:231:9
at Ping.onOperationComplete [as _callback] (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\Pool.js:110:5)
at Ping.Sequence.end (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\sequences\Sequence.js:88:24)
at Ping.Sequence.OkPacket (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\sequences\Sequence.js:97:8)
at Protocol._parsePacket (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\Users\User\Desktop\qsell-project\node_modules\mysql\lib\Connection.js:103:28)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:597:20)