问题
I have a problem trying to configure postrgres with nodeJs, i followed this tutorial and i get a error that doesn't specify anything about what is wrong:
here is the stacktrace
Unhandled rejection Error: Include unexpected. Element has to be either a Model, an Association or an object.
at C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\lib\model.js:1976:15
at Array.map (native)
at conformOptions (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\lib\model.js:1941:39)
at Model.<anonymous> (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\lib\model.js:700:7)
at Model.tryCatcher (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\node_modules\bluebird\js\main\util.js:26:23)
at Promise._settlePromiseFromHandler (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\node_modules\bluebird\js\main\promise.js:503:31)
at Promise._settlePromiseAt (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\node_modules\bluebird\js\main\promise.js:577:18)
at Promise._settlePromiseAtPostResolution (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\node_modules\bluebird\js\main\promise.js:244:10)
at Async._drainQueue (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\node_modules\bluebird\js\main\async.js:128:12)
at Async._drainQueues (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\node_modules\bluebird\js\main\async.js:133:10)
at Immediate.Async.drainQueues (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\node_modules\bluebird\js\main\async.js:15:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
my model:
var express = require('express');
var models = require('../models');
var router = express.Router();
/* GET users listing. */
router.get('/', function (req, res, next) {
var User = models.User;
User.findById(1).then(function (user) {
console.log(user);
})
});
module.exports = router;
my router:
"use strict";
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define("User", {
username: DataTypes.STRING,
id: DataTypes.INTEGER,
email: DataTypes.STRING
});
return User;
};
回答1:
Is posible that you have a problem with the depth of your model path, check first if that is the correct path. Alternatively, you can manage your require imports as suggested here, it will result really handy and useful.
来源:https://stackoverflow.com/questions/43938411/include-unexpected-element-has-to-be-either-a-model-an-association-or-an-objec