【发布时间】:2019-09-25 02:34:17
【问题描述】:
我正在使用带有 ATOM 的 ubuntu 18.04 笔记本电脑。当我尝试使用 sequelizer 时出现此错误。
UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误源于在 asyn 内部抛出 c 函数没有 catch 块,或者通过拒绝未使用 .catch() 处理的承诺。 (拒绝编号:1) (节点:16986)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。在未来,承诺拒绝不是 处理后的 Node.js 进程会以非零退出代码终止。
这是在我的 models.js 文件中:
const Sequelize = require('sequelize');
// Connect to the database
const sequelize = new Sequelize({
database: 'sequelize_lesson',
dialect: 'postgres',
});
// Define an Artist
const Artist = sequelize.define('artist', {
name: Sequelize.STRING,
});
// Define a Record
const Record = sequelize.define('record', {
title: Sequelize.STRING,
year: Sequelize.INTEGER,
cover_image_url: Sequelize.STRING,
});
// define the association between Artists --<< Records
// @see https://www.postgresql.org/docs/10/static/ddl-constraints.html#DDL-CONSTRAINTS-FK
Artist.hasMany(Record, { onDelete: 'cascade' });
// make the association from both directions
Record.belongsTo(Artist);
module.exports = {
Artist,
Record,
sequelize,
};
and in the file I am trying to run resetDb.js
const { sequelize } = require('./models');
const main = async () => {
await sequelize.sync({ force: true });
process.exit();
};
main();
//this is what I am trying to run with the command
node resetDb.js
【问题讨论】:
标签: javascript node.js sequelize.js