包括意外。元素必须是模型,关联或对象

时间:2017-05-12 12:59:50

标签: javascript node.js postgresql sequelize.js sequelize-cli

我在尝试使用nodeJs配置postrgres时遇到问题,我跟着这个tutorial,我得到的错误没有指出什么是错误的:

这是 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)

我的模特:

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;

我的路由器:

“use strict”;

module.exports = function(sequelize, DataTypes) {
  var User = sequelize.define("User", {
    username: DataTypes.STRING,
    id: DataTypes.INTEGER,
    email: DataTypes.STRING
  });

  return User;
};

1 个答案:

答案 0 :(得分:0)

您可能存在模型路径深度问题,请先检查是否是正确的路径。或者,您可以按照建议here管理您的需求导入,这将非常方便且有用。