How to seed uuidv4 with sequelize

Since it's included in the DataTypes package, would make sense to use what is already available as Matt suggested. You can use it in this way:

{
    ...,
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    ...
}

npm install uuid

import it on your seeder file

const { v4: uuidv4 } = require('uuid');

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

See more on the uuid documentation


just install uuid:

npm install uuid

and on your seed file:

const uuidv4 = require('uuid/v4');

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