【发布时间】:2019-08-04 13:46:44
【问题描述】:
我正在为我的 Node.Js/PSQL 项目的 ORM 使用 Sequalize。我正在创建一个种子文件来预填充我的数据库;但是,当我运行种子文件时,我收到与以下相关信息的字段之一相关的错误。使用带有
的 JSON 对象似乎存在问题错误
== 20170308131757-examples: migrating =======
ERROR: Invalid value { example: 'mk@kWO5r' }
定义
const example = sequelize.define('example', {
date: DataTypes.DATE
data: {
type: DataTypes.JSON,
allowNull: true
},
}, {});
种子文件
up: function (queryInterface) {
const examples = [];
examples.push({
date: new Date(),
data: {
data: dataFaker.string({ length: 8 })
},
createdAt: new Date(),
updatedAt: new Date()
});
for(let i = 0; i < 20; i++) {
testAlertLists.push({
date: new Date(),
data: {
data: dataFaker.string({ length: 8 })
},
createdAt: new Date(),
updatedAt: new Date()
});
}
return queryInterface.bulkInsert('examples', examples, {});
},
down: function (queryInterface) {
return queryInterface.bulkDelete('examples', null, {});
}
我保留了相关的代码片段来简化事情,所以如果需要我可以添加更多的字段和其他方面,如果有与可能来自简化事情的错误无关的小错别字,我可以修复如果找到的话。
问题似乎是 Sequalize 不接受插入中的 JSON 对象,但它在代码和表本身中都被定义为 JSON 对象(我检查过)。我尝试过几种不同的方式创建 Json,但除此之外我对这个问题有点困惑。将 JSON 对象与 psql 或 Sequalize 一起使用是否有问题?
【问题讨论】:
标签: javascript sql node.js sequelize.js psql