我将继续为 postges 的初始数据加载种子。我可以通过创建 seedfile.js 来为多个表执行此操作。但我无法自动处理表之间的关系。
// user_seeds.js
up: function (queryInterface, Sequelize) {
return queryInterface.bulkInsert(table, [{
uid: 1, //primary key autogenerated
name: 'John doe',
email: 'john@doe.com',
created_at,
updated_at
}], {});
// roles_seeds.js
up: function (queryInterface, Sequelize) {
return queryInterface.bulkInsert(table, [{
uid: 1, //this should be comes from user table to this filed automatically after the creation of first record in user table
name: 'admin',
email: 'john@doe.com',
created_at,
updated_at
}, {
id: 2,
name: 'user',
created_at,
updated_at
}]);
如何在不进行硬编码的情况下自动将主键作为外键传递给另一个表。