首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sequelize-cli db:seed返回'Unhandled rejection TypeError: undefined is not a function‘

sequelize-cli db:seed返回'Unhandled rejection TypeError: undefined is not a function‘
EN

Stack Overflow用户
提问于 2015-10-02 02:44:55
回答 2查看 1.7K关注 0票数 0

我正在使用sequelize-cli (v1.9.1),并试图在运行db:migration之后进行种子设定,但在运行db:seed时,我一直收到以下错误消息

代码语言:javascript
复制
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)

下面是我的种子文件:

代码语言:javascript
复制
'use strict';

module.exports = {
    up: function (queryInterface, Sequelize) {

        /*
         Add altering commands here.
         Return a promise to correctly handle asynchronicity.

         Example:
         return queryInterface.bulkInsert('Person', [{
         name: 'John Doe',
         isBetaMember: false
         }], {});
         */
        return queryInterface.bulkInsert('Users', [{
            id: Sequelize.UUIDV4,
            username: 'someone@email.com',
            email: 'someone@email.com'
        }], {});
    },

    down: function (queryInterface, Sequelize) {
        /*
         Add reverting commands here.
         Return a promise to correctly handle asynchronicity.

         Example:
         return queryInterface.bulkDelete('Person', null, {});
         */
        return queryInterface.bulkDelete('Users', null, {});
    }
};
EN

回答 2

Stack Overflow用户

发布于 2016-03-31 18:19:03

使用

代码语言:javascript
复制
sequelize db:seed:all

并为每个对象分别添加updatedDate{updatedAt:'2016-03-31T08:00:10.354Z'}和createdDate {createdAt:'2016-03-31T08:00:10.354Z'}。

票数 1
EN

Stack Overflow用户

发布于 2015-10-26 02:53:26

试试这条路

代码语言:javascript
复制
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() }
    ])
  ];
}

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32894687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档