gpt4 book ai didi

sequelize.js - 未处理的拒绝类型错误 : Dependency name must be given as a not empty string

转载 作者:行者123 更新时间:2023-12-04 05:12:32 24 4
gpt4 key购买 nike

当代码命中 require('./models').sequelize.sync() 时出现此错误. ( models 是通过运行命令创建的目录 sequelize init )谁能给我一些有关导致此错误的提示?

> node src/server.js

Unhandled rejection TypeError: Dependency name must be given as a not empty string
at /Users/syg/Repos/example/node_modules/sequelize/node_modules/toposort-class/toposort.js:37:31
at Array.forEach (native)
at Toposort.self.add (/Users/syg/Repos/example/node_modules/sequelize/node_modules/toposort-class/toposort.js:35:22)
at /Users/syg/Repos/example/node_modules/sequelize/lib/model-manager.js:89:12
at Array.forEach (native)
at ModelManager.forEachModel (/Users/syg/Repos/example/node_modules/sequelize/lib/model-manager.js:58:15)
at /Users/syg/Repos/example/node_modules/sequelize/lib/sequelize.js:862:23
at tryCatcher (/Users/syg/Repos/example/node_modules/sequelize/node_modules/bluebird/js/main/util.js:24:31)
at Promise._settlePromiseFromHandler (/Users/syg/Repos/example/node_modules/sequelize/node_modules/bluebird/js/main/promise.js:454:31)
at Promise._settlePromiseAt (/Users/syg/Repos/example/node_modules/sequelize/node_modules/bluebird/js/main/promise.js:530:18)
at Promise._settlePromiseAtPostResolution (/Users/syg/Repos/example/node_modules/sequelize/node_modules/bluebird/js/main/promise.js:224:10)
at Async._drainQueue (/Users/syg/Repos/example/node_modules/sequelize/node_modules/bluebird/js/main/async.js:182:12)
at Async._drainQueues (/Users/syg/Repos/example/node_modules/sequelize/node_modules/bluebird/js/main/async.js:187:10)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/syg/Repos/example/node_modules/sequelize/node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:358:17)

我正在使用 sequelize@3.2.0HapiJS .可以找到类似的 repo here . (这个 repo 确实有效,即使 sequelize 升级到最新版本)

最佳答案

这是由于根据之前版本的 sequelize 声明了外键。

根据最新版本“sequelize”:“^4.31.2”,添加外键的正确方法是-

addressId: {
type: DataTypes.INTEGER,
references: {
model: 'addresses',
key: 'id'
}
}

我宣布它为
addressId: {
type: DataTypes.INTEGER,
references: 'addresses',
referencesKey: 'id'
}

关于sequelize.js - 未处理的拒绝类型错误 : Dependency name must be given as a not empty string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30699742/

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