두 테이블 사이에 내부 조인을 수행하려고합니다. 첫 번째 것은 SmartMonument라는 데이터베이스에 있고 두 번째 데이터베이스는 SmartMonumentCB라는 데이터베이스에 있습니다. 'database.js'에서두 개의 서로 다른 데이터베이스에서 두 테이블 사이의 내부 조인을 sequelize
(SmartMonument 참조) :
가const CompaniesForClient=sequelize.define('cfc', {
scrapperName: {type: Sequelize.STRING, allowNull: false},
clientID : {type: Sequelize.INTEGER(10), allowNull: false}
});
CompaniesForClient.sync();
module.exports={sequelize, CompaniesForClient};
번째 테이블 인 :
const Companies = sequelize.define('companies', {
scrapperName: {type: Sequelize.STRING, allowNull: false},
scrapperAddress: {type: Sequelize.STRING(500)}
});
Companies.sync();
module.exports = {sequelize, Companies};
여기
그 테이블의 초기화를위한 코드 두 테이블 모두 잘 작성된 다음 scrapperName 필드에 관련 테이블이 모두 포함되도록 무언가를 추가하려고합니다.나는 그런처럼 수행하려고 :
CompaniesForClient.findAll({where:{clientID: param}, include: [{model: Companies}];
:
CompaniesForClient.hasOne(CompaniesDB.Companies, {foreignKey: 'scrapperName'});
내 목표는 같은 하나 개의 요청에 회사의 모든 분야와 모든 CompaniesForClient 필드를 읽을 수 있도록 ultimatly입니다
지금 다음 오류가 발생합니다.
Unhandled rejection SequelizeDatabaseError: Cannot add foreign key constraint at Query.formatError(/home/ubuntu/backendDev/node_modules/sequelize/lib/dialects/mysql/query.js:222:16) at Query.connection.query [as onResult] (/home/ubuntu/backendDev/node_modules/sequelize/lib/dialects/mysql/query.js:55:23) at Query.Command.execute (/home/ubuntu/backendDev/node_modules/mysql2/lib/commands/command.js:30:12) at Connection.handlePacket (/home/ubuntu/backendDev/node_modules/mysql2/lib/connection.js:515:28) at PacketParser.onPacket (/home/ubuntu/backendDev/node_modules/mysql2/lib/connection.js:94:16) at PacketParser.executeStart (/home/ubuntu/backendDev/node_modules/mysql2/lib/packet_parser.js:77:14) at Socket. (/home/ubuntu/backendDev/node_modules/mysql2/lib/connection.js:102:29) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at addChunk (_stream_readable.js:266:12) at readableAddChunk (_stream_readable.js:253:11) at Socket.Readable.push (_stream_readable.js:211:10) at TCP.onread (net.js:585:20)