我正在尝试使用knex来播种数据库.在贡献者的帮助下,我成功地在一张桌子上播种了我需要采取的几个步骤:
>我需要从几个外部表中提取id值,这样我就可以填充种子表的外键值.
>在种子表中生成n条记录.
>填充表格.
如上所述,我在一张桌子上工作.因为我比一个屋顶大头钉更聪明,并且必须为另一个表做几乎完全相同的事情,我只是复制了第一个种子文件中的工作,将其放入第二个种子文件中,进行了一些适当的修改(具体而言),在第二个表中,我只需要在此时填充1个外键值)并且……它不起作用.
我不知所措.当然,我在这段代码中遗漏了一些愚蠢的小东西,但我找不到它.我正在尝试播种一个单元表,我必须使用properties.id值填充它.
exports.seed = function(knex,Promise) { console.log('seeding the %s table...',tableName); Promise.resolve([ 'properties',]) .map(function(table) { // Pull foreign key values (property_id) var ids = knex.select('id').from(table).pluck('id'); // AT THIS POINT THE ids VARIABLE HAS A VALUE return ids; }) .spread(function(properties) { // BUT I NEVER SEE THIS LOG PRINT console.log('SPREADING UNITS'); }); };
我究竟做错了什么?我把.catch()和.error()放到了这个东西里,但没有任何东西写入日志.不知何故,我似乎永远不会陷入.spread(…)方法.
UPDATE
{ client: { Formatter: { [Function: Formatter_MysqL] super_: [Function: Formatter] },Raw: { [Function: Raw_MysqL] super_: [Object] },Transaction: { [Function: Transaction_MysqL] super_: [Object] },QueryBuilder: { [Function: QueryBuilder_MysqL] super_: [Object] },QueryCompiler: { [Function: QueryCompiler_MysqL] super_: [Function: QueryCompiler] },migrationConfig: { tableName: 'knex_migration',directory: './migrations' },seedConfig: { directory: './seeds' },Runner: { [Function: Runner_MysqL] super_: [Function: Runner] },connectionSettings: { host: '127.0.0.1',port: '3306',user: 'root',password: '',database: 'realster',timezone: 'UTC',charset: 'utf8',debug: false },Pool: { [Function: Pool_MysqL] super_: [Function: Pool] },databaseName: 'realster',pool: { client: [Circular],config: [Object],genericPool: [Object] },_events: { start: [Function],query: [Function] },Seeder: { [Function: Seeder_MysqL] super_: [Function: Seeder] } },_single: { table: 'properties',pluck: 'id' },_statements: [ { grouping: 'columns',value: [Object] },{ grouping: 'columns',type: 'pluck',value: 'id' } ],_errors: [],_joinFlag: 'inner',_boolFlag: 'and',_notFlag: false,and: [Circular],_method: 'pluck' }