我每次执行下面的代码时都会遇到此错误,我似乎无法弄清楚
未处理拒绝TypeError:val.replace不是函数 在Object.SqlString.escape
var connection = new Sequelize('database', 'root', 'phase_99');
var User = connection.define('user', {title: Sequelize.STRING});
var Project = connection.define('project', {title: Sequelize.STRING});
User.hasMany(Project);
Project.belongsTo(User);
connection.sync().then(() => {
User.create({title: 'user'})
.then(user => {
var project = Project.create({title: 'ISD Corp'});
user.addProject({project});
})
});
答案 0 :(得分:2)
您正在创建产品之前添加产品,因为这是一个承诺执行此操作
User.create({title: 'user'})
.then(user => {
Project.create({title: 'ISD Corp'}).then(project => {
user.addProject({project});
})
})
});