sequelize-cli db:种子返回'未处理的拒绝TypeError:undefined不是函数'

时间:2015-10-01 18:44:55

标签: node.js postgresql sequelize.js

我正在使用sequelize-cli(v1.9.1)并且我在运行db:migration后尝试播种但我在运行{{1时}时仍然收到以下错误消息}}:

db:seed

这是我的种子文件的样子:

Sequelize [Node: 0.12.7, CLI: 1.9.1, ORM: 3.9.0]

Loaded configuration file "src/server/config/config.json".
Using environment "development".
Using gulpfile /usr/local/lib/node_modules/sequelize-cli/lib/gulpfile.js
Starting 'db:seed'...
Finished 'db:seed' after 96 ms
== 20151001101051-admin-user-seed: migrating =======
Unhandled rejection TypeError: undefined is not a function
    at Object.SqlString.escape (/Users/me/WebstormProjects/my-project/node_modules/sequelize/lib/sql-string.js:87:15)
    at Object.QueryGenerator.escape (/Users/me/WebstormProjects/my-project/node_modules/sequelize/lib/dialects/postgres/query-generator.js:924:22)
    at Object.<anonymous> (/Users/me/WebstormProjects/my-project/node_modules/sequelize/lib/dialects/postgres/query-generator.js:356:23)
    at Array.map (native)
    at Object.<anonymous> (/Users/me/WebstormProjects/my-project/node_modules/sequelize/lib/dialects/postgres/query-generator.js:352:23)
    at arrayEach (/Users/me/WebstormProjects/my-project/node_modules/lodash/index.js:1289:13)
    at Function.<anonymous> (/Users/me/WebstormProjects/my-project/node_modules/lodash/index.js:3345:13)
    at Object.QueryGenerator.bulkInsertQuery (/Users/me/WebstormProjects/my-project/node_modules/sequelize/lib/dialects/postgres/query-generator.js:350:13)
    at QueryInterface.bulkInsert (/Users/me/WebstormProjects/my-project/node_modules/sequelize/lib/query-interface.js:576:33)
    at Object.module.exports.up (/Users/me/WebstormProjects/my-project/src/server/seeders/20151001101051-admin-user-seed.js:17:31)
    at Object.tryCatcher (/usr/local/lib/node_modules/sequelize-cli/node_modules/bluebird/js/main/util.js:26:23)
    at Object.ret (eval at <anonymous> (/usr/local/lib/node_modules/sequelize-cli/node_modules/bluebird/js/main/promisify.js:163:12), <anonymous>:13:39)
    at module.exports.redefine.Class._exec (/usr/local/lib/node_modules/sequelize-cli/node_modules/umzug/lib/migration.js:49:23)
    at module.exports.redefine.Class.up (/usr/local/lib/node_modules/sequelize-cli/node_modules/umzug/lib/migration.js:33:17)
    at null.<anonymous> (/usr/local/lib/node_modules/sequelize-cli/node_modules/umzug/index.js:78:28)
    at Object.tapHandler (/usr/local/lib/node_modules/sequelize-cli/node_modules/bluebird/js/main/finally.js:63:44)
    at Object.tryCatcher (/usr/local/lib/node_modules/sequelize-cli/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/sequelize-cli/node_modules/bluebird/js/main/promise.js:507:31)
    at Promise._settlePromiseAt (/usr/local/lib/node_modules/sequelize-cli/node_modules/bluebird/js/main/promise.js:581:18)
    at Promise._settlePromises (/usr/local/lib/node_modules/sequelize-cli/node_modules/bluebird/js/main/promise.js:697:14)
    at Async._drainQueue (/usr/local/lib/node_modules/sequelize-cli/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/usr/local/lib/node_modules/sequelize-cli/node_modules/bluebird/js/main/async.js:133:10)

2 个答案:

答案 0 :(得分:1)

使用

sequelize db:seed:all

并添加createdDate {createdAt:&#39; 2016-03-31T08:00:10.354Z&#39;}和updatedDate {updatedAt:&#39; 2016-03-31T08:00:10.354Z&#39;分别是每个对象。

答案 1 :(得分:0)

试试这种方式

up: function (queryInterface, Sequelize) {
  console.log(User);
  return [
    queryInterface.bulkInsert('Users', [
      { username: "user1", createdAt: Date.now(), updatedAt: Date.now() },
      { username: "user2", createdAt: Date.now(), updatedAt: Date.now() }
    ])
  ];
}

或者使用可以使用sequelize-fixture来播种或测试数据插入

https://github.com/domasx2/sequelize-fixtures