Reputation: 2829
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()
}]);
Upvotes: 15
Views: 15279
Reputation: 424
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
Upvotes: 7
Reputation: 2718
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,
...
}
Upvotes: 8
Reputation: 11543
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()
}],
{});
Upvotes: 14