Unhandled rejection TypeError: Dependency name must be given as a not empty string
Unhandled rejection TypeError: Dependency name must be given as a not empty string
我在代码点击 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.0
和 HapiJS
。可以找到类似的回购 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'
}
我在代码点击 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.0
和 HapiJS
。可以找到类似的回购 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'
}