Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to seed uuidv4 with sequelize

I am trying to seed a uuid using sequilize generateUUID but i get this error Seed file failed with error: sequelize.Utils.generateUUID is not a function TypeError: sequelize.Utils.generateUUID is not a function

how do i seed a UUID?

    return queryInterface.bulkInsert('companies', [{
        id: sequelize.Utils.generateUUID(),
        name: 'Testing',
        updated_at: new Date(),
        created_at: new Date()
    }]);
like image 489
WalksAway Avatar asked Sep 24 '17 09:09

WalksAway


People also ask

What is seed in Sequelize?

Seed files are some change in data that can be used to populate database tables with sample or test data. Let's create a seed file which will add a demo user to our User table. npx sequelize-cli seed:generate --name demo-user. exports = { up: (queryInterface, Sequelize) => {

What is UUID Sequelize?

Extends: src/data-types.js~ABSTRACT → UUID. A column storing a unique universal identifier.


1 Answers

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,
    ...
}
like image 73
Hichame Yessou Avatar answered Sep 24 '22 14:09

Hichame Yessou