mysql/mariadb dates allow the use of zero value in dates '0000-00-00 00:00:00'
Yet using this dates with Sequelize 3 causes an error when trying to update them to a proper date
CREATE TABLE `test` (
`key` char(255) NOT NULL,
`ttl` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
KEY `key` (`key`)
);
var Test = sequelize.define('test', {
key: {
type: Sequelize.STRING,
primaryKey: true
},
ttl: {
type : Sequelize.DATE,
defaultValue: '0000-00-00 00:00:00'
//or defaultValue: new Date('0000-00-00 00:00:00')
//or no default value all produce the same result
},
}, {
timestamps: false,
freezeTableName: true
});
Test.create({key: 'KEY_' + process.pid})
.then(function (row) {
return Test.findById(row.key);
}).then(function (row) {
return row.set({'ttl': new Date()}).save();
}).finally(sequelize.close.bind(sequelize));
Running this code I get the following error -
Unhandled rejection TypeError: originalValue.getTime is not a function
at Instance.set (node_modules/sequelize/lib/instance.js:348:68)
at Instance.set (node_modules/sequelize/lib/instance.js:292:16)
at null.<anonymous> (test.js:33:14)
at tryCatcher (node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (node_modules/bluebird/js/main/promise.js:507:31)
at Promise._settlePromiseAt (node_modules/bluebird/js/main/promise.js:581:18)
at Async._drainQueue (node_modules/bluebird/js/main/async.js:128:12)
at Async._drainQueues (node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:383:17)
mysql/mariadb dates allow the use of zero value in dates '0000-00-00 00:00:00'
Yet using this dates with Sequelize 3 causes an error when trying to update them to a proper date
Running this code I get the following error -