我试图在Sequelize 4.0中存储UTC ISO 8601日期时间对象但是我只能在我的模型中指定DateType.Date。当我在插入数据时使用格式化的ISO 8601日期时间字符串时,我得到一个解析错误:
"Incorrect datetime value: '2018-05-14T14:29:21.338Z' for column 'columnName' at row 1"
我的模型如下所示(简化问题):
module.exports = (sequelize, DataTypes) => {
var deviceData = sequelize.define('deviceData', {
steps: DataTypes.INTEGER,
recordedOn: DataTypes.DATE,
batteryLevel: DataTypes.INTEGER,
}, {});
return deviceData;
};
数据库配置看起来像;
module.exports = {
development: {
database: 'DATABASENAME',
username: 'MYUSERNAME',
password: 'MYPASSWORD',
dialect: 'mysql',
host: 'HOSTNAME'
},
testing: {
dialect: 'sqlite',
storage: ':memory:',
logging: false
}
};
我宣布我的Sequelize实例如下:
const fs = require('fs');
const path = require('path');
const basename = path.basename(__filename);
const Sequelize = require('sequelize');
let config = require('../config/db.js');
const db = {};
db.sequelize = new Sequelize(config.database, config.username, config.password, config);
db.Sequelize = Sequelize;
module.exports = db;
我无法决定是否应该在插入数据库之前将所有ISO 8601日期时间对象解析为datetime对象,或者Sequelize是否能够在我的数据库中解释ISO 8601日期时间对象和datetime对象。