TypeError:defineCall不是Sequelize.import

时间:2017-05-05 06:01:10

标签: sequelize.js

将我的User.js模型定义为低于异常

错误

  

PS C:\ Users \ meghshyam \ Documents \ express_node_mysql_handlebars>节点   server.js   C:\ Users \用户meghshyam \文件\ express_node_mysql_handlebars \ node_modules \ sequelize \ lib中\ sequelize.js:691       this.importCache [path] = defineCall(this,DataTypes);                                ^

     

TypeError:defineCall不是函数       在Sequelize.import(C:\ Users \ meghshyam \ Documents \ express_node_mysql_handlebars \ node_modules \ sequelize \ lib \ sequelize.js:691:30)       在C:\ Users \ meghshyam \ Documents \ express_node_mysql_handlebars \ models \ index.js:23:36       at Array.forEach(native)       在对象。 (C:\用户\ meghshyam \文件\ express_node_mysql_handlebars \模型\ index.js:22:4)       在Module._compile(module.js:409:26)       at Object.Module._extensions..js(module.js:416:10)       在Module.load(module.js:343:32)       在Function.Module._load(module.js:300:12)       在Module.require(module.js:353:17)       at require(internal / module.js:12:17)       在对象。 (C:\用户\ meghshyam \文件\ express_node_mysql_handlebars \ server.js:16:10)       在Module._compile(module.js:409:26)       at Object.Module._extensions..js(module.js:416:10)       在Module.load(module.js:343:32)       在Function.Module._load(module.js:300:12)       在Function.Module.runMain(module.js:441:10)

 "use strict";

 module.exports = function(sequelize, DataTypes) {
 var User = sequelize.define("User", 
 {
 //timestamps: true,
 // id:DataTypes.INTEGER,
  username:{ 
  type:DataTypes.STRING,
  validate:{
    isEmail:true
  }
},
password: {
  type: DataTypes.STRING,
  validate:{
    len:[6,12],
    notNull:true,
    notEmpty:true
  }
},
 role:{
  type: DataTypes.INTEGER,
  validate:{
    notNull:true,
    notEmpty:true,
    isNumeric:true
  },
  }
 },

  {
 classMethods: {
 associate: function(models) {
  // Associating Author with Posts
  // When an Author is deleted, also delete any associated Posts
 // User.belongsTo(models.Student, {
 //   onDelete: "cascade"
 // });
//user has one teacher record
//   User.belongsTo(models.Teacher, {
//    onDelete: "cascade"
  });
  }
  }
  }
  );
return User;
 };

2 个答案:

答案 0 :(得分:0)

这通常是由于在object(GuzzleHttp\Psr7\Response)#611 (6) { ["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=>string(2) "OK" ["statusCode":"GuzzleHttp\Psr7\Response":private]=>int(200) ["headers":"GuzzleHttp\Psr7\Response":private]=>array(11) { ["Content-Type"]=> array(1) { [0]=> string(24) "application/vnd.api+json" } ["Date"]=> array(1) { [0]=> string(29) "Tue, 26 Mar 2019 19:55:02 GMT" } ["Referrer-Policy"]=> array(1) { [0]=> string(24) "origin-when-cross-origin" } ["Server"]=> array(1) { [0]=> string(8) "forge-dm" } ["Strict-Transport-Security"]=> array(1) { [0]=> string(35) "max-age=31536000; includeSubDomains" } ["X-Content-Type-Options"]=> array(1) { [0]=> string(7) "nosniff" } ["X-Frame-Options"]=> array(1) { [0]=> string(4) "DENY" } ["X-Request-Id"]=> array(1) { [0]=> string(36) "b747247f-b93b-4557-ae11-821b76fc8bba" } ["X-XSS-Protection"]=> array(1) { [0]=> string(13) "1; mode=block" } ["Content-Length"]=> array(1) { [0]=> string(4) "1087" } ["Connection"]=> array(1) { [0]=> string(10) "keep-alive" } } ["headerNames":"GuzzleHttp\Psr7\Response":private]=>array(11) { ["content-type"]=>string(12) "Content-Type" ["date"]=>string(4) "Date" ["referrer-policy"]=>string(15) "Referrer-Policy" ["server"]=>string(6) "Server" ["strict-transport-security"]=>string(25) "Strict-Transport-Security" ["x-content-type-options"]=>string(22) "X-Content-Type-Options" ["x-frame-options"]=>string(15) "X-Frame-Options" ["x-request-id"]=>string(12) "X-Request-Id" ["x-xss-protection"]=>string(16) "X-XSS-Protection" ["content-length"]=>string(14) "Content-Length" ["connection"]=>string(10) "Connection" } ["protocol":"GuzzleHttp\Psr7\Response":private]=>string(3) "1.1" ["stream":"GuzzleHttp\Psr7\Response":private]=>object(GuzzleHttp\Psr7\Stream)#635 (7) { ["stream":"GuzzleHttp\Psr7\Stream":private]=> resource(47) of type (stream) ["size":"GuzzleHttp\Psr7\Stream":private]=> NULL ["seekable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["readable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["writable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["uri":"GuzzleHttp\Psr7\Stream":private]=> string(10) "php://temp" ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=> array(0) { } } } 中导入不是Sequelize模型的文件引起的。您的模型目录中是否有不是模型的东西?就我而言,这是因为它正在提取我的测试文件以及模型,这些文件位于同一目录中。尝试在index.js中添加另一张支票,以在其中构建文件列表,以排除以index.js结尾的任何内容(或任何适合您的等效内容)。

答案 1 :(得分:0)

我遇到了同样的问题,我并没有理解你的方法,但对我来说却是这样:

var CurrencyShop = require('./models/CurrencyShop.js')(sequelize, Sequelize.DataTypes);
require('./models/Users.js')(sequelize, Sequelize.DataTypes);
require('./models/UserItems.js')(sequelize, Sequelize.DataTypes);