我的代码
const connection = new Sequelize('db','miki','passw', {
host: 'localhost',
dialect : 'sqlite',
storage: 'db.sqlite',
operatorsAliaases :'false'
})
const user = connection.define('User', {
name : Sequelize.STRING,
bio : Sequelize.TEXT
});
connection.sync({
logging : console.log
})
.then(() => {
User.create({
name: 'Beba',
bio: 'devops engineer'
})
})
.then(() => {
console.log('Connectio to db established');
})
.catch(() => {
console.error('unable to connect to db', err);
});
我出错了
Executing (default): CREATE TABLE IF NOT EXISTS `Users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(255), `bio` TEXT, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL);
Executing (default): PRAGMA INDEX_LIST(`Users`)
Unhandled rejection ReferenceError: err is not defined
我看过类似的SO帖子,但是答案建议使用Promise重写代码。在将项目添加到数据库时,是否有任何简单的同步解决方案可以捕获错误?