我正在使用sequelize-cli (v1.9.1),并试图在运行db:migration之后进行种子设定,但在运行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)下面是我的种子文件:
'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, {});
}
};发布于 2016-03-31 18:19:03
使用
sequelize db:seed:all并为每个对象分别添加updatedDate{updatedAt:'2016-03-31T08:00:10.354Z'}和createdDate {createdAt:'2016-03-31T08:00:10.354Z'}。
发布于 2015-10-26 02:53:26
试试这条路
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://stackoverflow.com/questions/32894687
复制相似问题