【发布时间】:2016-06-12 00:29:09
【问题描述】:
我无法让sequelize.sync() 工作。在每个模型定义上调用 sync() 可以完美地工作,但从 sequelize 实例调用它似乎没有任何作用,就像模型管理器中没有注册模型一样。
考虑以下几点:
function syncAll() {
console.log('Retrieving exported models...')
let models = require('./models')
for(var modelName in models) {
let model = models[modelName]
// define() just wraps a regular sequelize.define() call
// model.define().sync() works!
model.define()
}
console.log('All exported models have been defined! Syncing database...')
sequelize.sync({
logging: true
}).then(function() {
// The operation completes but no command is executed in the DB
console.log('Database synchronization complete!')
}).catch(function(error) {
console.log("Database synchronization error:\n\t${error}")
})
}
只是想了解我缺少什么,为什么批量同步对我不起作用?
AFAIK 我只需要在调用 sequelize.sync() 之前定义的所有模型,对吧?!
编辑 1
关于我的环境的一些信息:我在 debian 下使用 node 5.6 和 postgres
编辑 2
发现问题。请参阅已接受答案的结尾...
【问题讨论】:
标签: node.js typescript sequelize.js