mysql - Sequelize 错误 - lodash 没有方法 "template"

标签 mysql node.js sequelize.js

我刚刚通过 npm 安装了 Sequelize 和 MySQL 模块,但遇到了错误。

我可以成功查询我的模型,但尝试创建新模型实例会导致 query-generator.js 文件中出现错误。

我的代码:

var Sequelize = require('sequelize')
  , sequelize = new Sequelize('databasename', 'username', 'password');

var User = sequelize.define('users', {
  email: Sequelize.STRING,
  fname: Sequelize.STRING,
  lname: Sequelize.STRING,
});

// WORKS
User.find(1)
  .success(function(user) {
    console.log('User found');
  }).
  error(function(err) {
    console.log('Error locating user', err);
  });

// FAILS
User.create({
  email : 'test@example.com',
  fname : 'John',
  lname : 'Doe'
})
.success(function(user) {
  // Do something
})
.error(function(err) {
  // Do something
});

这里是错误

~/Project/node_modules/sequelize/lib/dialects/abstract/query-generator.js:156
      return Utils._.template(query)(replacements)
                 ^
TypeError: Object function lodash(value) {
      // don't wrap if already wrapped, even if wrapped by a different `lodash` constructor
      return (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__'))
   ? value
   : new lodashWrapper(value);
} has no method 'template'
at Object.module.exports.QueryGenerator.insertQuery (~/Project/node_modules/sequelize/lib/dialects/abstract/query-generator.js:156:22)

最佳答案

原来我的本地版本的 npm 正在获取 Emmet 特定的 lodash 版本。运行

npm install lodash

获取了这个 repo https://github.com/emmetio/lodash而不是 https://github.com/lodash/lodash

运行

npm install lodash --force

并重新安装 Sequelize 解决了我的问题。

关于mysql - Sequelize 错误 - lodash 没有方法 "template",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23815763/

相关文章:

sequelize.js - 如何总结与满足参数的其他模型相关的列?

mysql - 如何使用 nodeJS 在 Sequelize 中包含的对象数组中执行查询

php - 口语变体关系数据库设计的最佳实践

php - 无法通过 PHP 表单插入到我的 sql 表中

php - 从 PHP 中的 GET 变量的数组中打印?

php - 如何从连接表中返回数据

mysql - 序列化的 SQL

node.js - NPM - 无法安装 socket.IO

node.js - Mongoose 在 _doc 对象中返回数据

python - 使用nodejs接收python代码