我正在使用Sequelize创建数据库模式。而且我找不到如何在多对多关系中设置外键名称。
我有一个 investment_manager 表
const Investment_manager = sequelize.define('investment_manager', {
im_id : {type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true},
im_name : {type: Sequelize.STRING, allowNull: false}
// Other fields ....
});
项目表
const Project = sequelize.define('project', {
project_id : {type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true},
project_name : {type: Sequelize.STRING, allowNull: false},
// Other fields ....
});
asso_project_im 表
const Asso_project_im = sequelize.define('asso_project_im', {
asso_id: {type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true},
// Other fields ....
});
我使用 belongsToMany
连接表investment_manager.belongsToMany(project, {as: 'im', through: 'asso_project_im', foreign_key: 'im_id'});
project.belongsToMany(investment_manager, {as: 'project', through: 'asso_project_im', foreign_key: 'project_id'});
我想在名为'im_id'和'project_id'的Asso_project_im表中创建外键,有什么办法吗?非常感谢!