I am using an ubuntu 18.04 laptop with ATOM. When I try to use sequelizer I get this error.
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an asyn c function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:16986) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
This is in my models.js file:
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
It's telling you that you need to using a try/catch
or a .catch()
since there is an exception being thrown in a Promise. Possibly just because you have process.exit()
instead of process.exit(0)
? In either case, use something like this to see the error:
const main = async () => {
try {
await sequelize.sync({ force: true });
process.exit(0); // exit code 0 is normal
} catch (err) {
// this will show the error
console.log('There was an error!', err);
}
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.