sprint
MVC 구조

- Batch mode에서 schema, seed 파일 적용하는 방법
1 2
mysql -u root -p < PATH/[schema or seed].sql -D[database] // -D 커맨드는 지정한 파일을 import할 데이터베이스를 선택하는 명령어
- Node.js mysql 모듈로 bulk insert 하는 방법
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Bulk insert const sql = "INSERT INTO customers (name, address) VALUES ?"; const params = [ ["John", "Highway 71"], ["Peter", "Lowstreet 4"], ["Amy", "Apple st 652"], ["Hannah", "Mountain 21"], ["Michael", "Valley 345"], ["Sandy", "Ocean blvd 2"], ["Betty", "Green Grass 1"], ["Richard", "Sky st 331"], ["Susan", "One way 98"], ["Vicky", "Yellow Garden 2"], ["Ben", "Park Lane 38"], ]; con.query(sql, [params], function (err, result) { if (err) throw err; console.log("Number of records inserted: " + result.affectedRows); });
1 2 3 4 5 6 7 8 9 10 11
// Result Object { fieldCount: 0, affectedRows: 14, insertId: 0, // Insert로 생성되는 insertId를 PK로 사용하여 조인 테이블에서 FK로 참조할 수 있음 serverStatus: 2, warningCount: 0, message: '\'Records:14 Duplicated: 0 Warnings: 0', protocol41: true, changedRows: 0 }
- FK(외래키)가 존재하는 테이블의 경우, 테이블 DELETE 및 TRUNCATE 실행 시, Cannot truncate a table referenced in a foreign key constraint 오류가 발생
- 해결법
1 2 3
SET FOREIGN_KEY_CHECKS = 0; -- Disable foreign key checking. TRUNCATE TABLE [Table_name]; SET FOREIGN_KEY_CHECKS = 1; -- Enable foreign key checking.
- 해결법
