这是我的 managedb.js
var Sequelize = require('sequelize-postgres').sequelize;
var postgres = require('sequelize-postgres').postgres;
var db = new Sequelize('test', 'postgres', 'postgres', {
dialect: 'postgres'
});
var models = [
'user'
];
models.forEach(function(model) {
module.exports[model] = db.import(__dirname + '/' + model);
});
module.exports.db = db;
这是我的 user.js
var sequelize = require("sequelize");
var seq = require("./managedb");
var db = seq.db;
var Project = db.define('Project', {
title: sequelize.STRING,
description: sequelize.TEXT
});
我很困惑为什么会收到此错误:
var Project = db.define('Project', {
^
TypeError: Cannot call method 'define' of undefined
为什么会出现这种情况?我是否导出变量错误?或者我是否必须向 managedb.js 添加一个 db.sync() 语句?