gpt4 book ai didi

javascript - 在 Sequelize 中播种的问题

转载 作者:行者123 更新时间:2023-12-03 22:19:48 25 4
gpt4 key购买 nike

我正在从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com