我正在从 sequelize docs 做例子,我创建了用户表:npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string
运行迁移,然后当我运行这个种子时:
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('Users', [{
firstName: 'John',
lastName: 'Doe',
email: 'demo@demo.com',
createdAt: Date.now(),
updatedAt: Date.now()
}], {});
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('Users', null, {});
}
};
有错误:
column "createdAt" is of type timestamp with time zone but expression is of type bigint
更新:
new Date().toISOString().slice(0, 19).replace('T', ' ')
解决了问题,但看起来不太好。有更好的解决方案吗?
最佳答案
您正在使用 Date.now()
,它为您提供纪元时间戳。而是使用返回 ISO 日期字符串的 new Date(). toISOString ()
。
关于javascript - 在 Sequelize 中播种的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56984410/