gpt4 book ai didi

javascript - 在 Ubuntu 18.04 上使用 Sequelize 时出现接收错误。在 Mac 上使用完全相同的文件不会发生错误

转载 作者:行者123 更新时间:2023-12-03 22:39:24 24 4
gpt4 key购买 nike

我正在使用带有 ATOM 的 ubuntu 18.04 笔记本电脑。当我尝试使用 sequelizer 时,出现此错误。

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.



这是在我的 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

最佳答案

它告诉您需要使用 try/catch.catch(),因为在 Promise 中抛出了异常。可能只是因为你有 process.exit() 而不是 process.exit(0) ?在任何一种情况下,使用类似的东西来查看错误:

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);
}
};

关于javascript - 在 Ubuntu 18.04 上使用 Sequelize 时出现接收错误。在 Mac 上使用完全相同的文件不会发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52373194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com