Node.js sequelize播种机中挂起的无效值承诺
我正在试着运行这个简单的播种机。 使用哈希函数时会发生此错误。在没有功能的情况下正确运行。Node.js sequelize播种机中挂起的无效值承诺,node.js,sequelize-cli,Node.js,Sequelize Cli,我正在试着运行这个简单的播种机。 使用哈希函数时会发生此错误。在没有功能的情况下正确运行。 如何散列我的密码 'use strict'; const bcrypt = require('bcryptjs'); async function hash(password) { const salt = await bcrypt.genSalt(10); const passwprdHash = await bcrypt.hash(password, salt);
如何散列我的密码
'use strict';
const bcrypt = require('bcryptjs');
async function hash(password) {
const salt = await bcrypt.genSalt(10);
const passwprdHash = await bcrypt.hash(password, salt);
return passwprdHash;
}
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('Users', [{
email: 'info@admin.ir',
username: 'admin',
password: hash('secret'),
name: 'admin',
family: 'admin',
mobile: '000000',
about: 'Fullstack webdeveloper',
active: true,
permission_group_id: 1,
createdAt: new Date(),
updatedAt: new Date()
}]);
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('Users', null, {});
}
};
错误是:
您需要等待哈希函数,因为它是异步的。像这样的事
'use strict';
const bcrypt = require('bcryptjs');
async function hash(password) {
const salt = await bcrypt.genSalt(10);
const passwprdHash = await bcrypt.hash(password, salt);
return passwprdHash;
}
module.exports = {
up: async (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('Users', [{
email: 'info@admin.ir',
username: 'admin',
password: await hash('secret'),
name: 'admin',
family: 'admin',
mobile: '000000',
about: 'Fullstack webdeveloper',
active: true,
permission_group_id: 1,
createdAt: new Date(),
updatedAt: new Date()
}]);
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('Users', null, {});
}
};
错误更改为“错误:意外标识符”@ashish modi