IntegrityError: 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (oneday
.gas_station
, CONSTRAINT gas_station_ibfk_1
FOREIGN KEY (brand
) REFERENCES gas_brand
(id
))
방법 1 : 참조 대상이 되는 테이블의 값을 먼저 입력 후 다시 실행
방법 2 : 참조 대상이 되는 테이블에 값을 입력한 후에도 동일한 오류가 반복된다면
SET foreign_key_checks = 0;
SET foreign_key_checks = 1;
위의 코드가 반영되지 않는다면, 외래키 기능 다시 추가
alter table gas_station
add foreign key (brand) references gas_brand(id)