• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Sequelize 错误:在 Index.js 未定义 defineCall

用户头像
it1352
帮助4

问题说明

我一直收到此续集错误

/node_modules/sequelize/lib/sequelize.js:508
      this.importCache[path] = defineCall(this, DataTypes);
                           ^
    TypeError: defineCall is not a function
    at module.exports.Sequelize.import             (/node_modules/sequelize/lib/sequelize.js:508:32)
at   /models/Index.js:16:33
at Array.forEach (native)
at Object.<anonymous> (/Users/vincentporta/Desktop/RCB_Classwork/cesarcell/models/Index.js:15:4)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)

我已将范围缩小到下面的 Index.js 文件中的注释代码

I've narrowed it down to the commented code in my Index.js file below

使用严格";

var fs        = require("fs");
var path      = require("path");
var Sequelize = require("sequelize");
var config    = require(path.join(__dirname, '..', 'config',    'config.json'))[env];
var sequelize = new Sequelize(config.database, config.username,  config.password, config);
var db        = {};

fs
  .readdirSync(__dirname)
  .filter(function(file) {
    return (file.indexOf(".") !== 0) && (file !== "index.js");
  })

下面这段注释的代码破坏了它<代码>//.forEach(函数(文件){//var model = sequelize.import(path.join(__dirname, file));//db[model.name] = 模型;//});

This commented code below breaks it //.forEach(function(file) { // var model = sequelize.import(path.join(__dirname, file)); // db[model.name] = model; // });

Object.keys(db).forEach(function(modelName) {
  if ("associate" in db[modelName]) {
    db[modelName].associate(db);
  }
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;

有谁知道为什么会出现这个错误?

Does anyone know why this error is occuring?

正确答案

#1

这通常意味着您正在尝试导入非 sequelize 对象.如果您的索引文件的名称是 Index.js 那么您需要在过滤器函数中更改它(第一个字母是大写)

This usually means you're trying to import a non-sequelize object. If the name of your index file is Index.js then you need to change it in your filter function (first letter is capital)

return (file.indexOf(".") !== 0) && (file !== "Index.js");

因为它区分大小写.还要检查您的导入文件夹中是否没有任何其他未定义续集模型的文件.如果只是将它们添加到您的过滤器功能中.

As it is case sensitive. Also check that there aren't any other files in your import folder which don't define sequelize model. If there are just add them to your filter function.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangbbjig
系列文章
更多 icon
同类精品
更多 icon
继续加载