我正在尝试使用 sequelize generate UUID 为 uuid 播种,但我收到此错误 Seed file failed with error: sequelize.Utils.generateUUID is not a function TypeError: sequelize.Utils.generateUUID is not a function我如何播种 UUID?

    return queryInterface.bulkInsert('companies', [{
        id: sequelize.Utils.generateUUID(),
        name: 'Testing',
        updated_at: new Date(),
        created_at: new Date()
    }]);

最佳答案

只需安装uuid:

npm install uuid

并在您的种子文件上:
const uuidv4 = require('uuid/v4');

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.bulkInsert('yourTableName', [
      {
        id: uuidv4()
      }],
 {});

关于node.js - 如何使用 sequelize 播种 uuidv4,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46388378/

10-16 20:04