【问题标题】:Issue with seeding in sequelizesequelize 中的播种问题
【发布时间】:2019-11-20 21:21:39
【问题描述】:

我正在做 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', ' ') 解决了问题,但看起来不太好。有没有更好的解决方案?

【问题讨论】:

    标签: javascript sequelize.js seeding


    【解决方案1】:

    您正在使用Date.now(),它会为您提供一个纪元时间戳。而是使用返回 ISO 日期字符串的 new Date(). toISOString ()

    【讨论】:

    • 现在我得到time zone "gmt+0300" not recognized。 Date() 的值为Thu Jul 11 2019 11:25:42 GMT+0300 (Moscow Standard Time)
    猜你喜欢
    • 1970-01-01
    • 2017-08-26
    • 2016-03-17
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 2011-04-11
    • 2018-08-28
    • 2020-03-18
    相关资源
    最近更新 更多