Closed Gaebobman closed 1 year ago
CREATE TABLE IF NOT EXISTS `home_database`.`visitor_info` (
`user_id` VARCHAR(13) COLLATE 'utf8mb3_bin' NOT NULL,
`enterance_time` DATETIME NOT NULL,
PRIMARY KEY (`user_id`, `enterance_time`))
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `home_database`.`water_usage` (
`usage_id` INT NOT NULL AUTO_INCREMENT,
`user_id` VARCHAR(13) COLLATE 'utf8mb3_bin' NULL DEFAULT NULL,
`START_TIME` DATETIME NOT NULL,
`END_TIME` DATETIME NOT NULL,
`PLACE` VARCHAR(45) COLLATE 'utf8mb3_bin' NOT NULL,
`AMOUNT` FLOAT NOT NULL,
PRIMARY KEY (`usage_id`),
CONSTRAINT `fk_water_usage_user_id`
FOREIGN KEY (`user_id`)
REFERENCES `home_database`.`visitor_info` (`user_id`))
ENGINE = InnoDB;
pymysql.err.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (home_database
.water_usage
, CONSTRAINT fk_water_usage_user_id
FOREIGN KEY (user_id
) REFERENCES visitor_info
(user_id
))')
pymysql.err.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (
home_database
.water_usage
, CONSTRAINTfk_water_usage_user_id
FOREIGN KEY (user_id
) REFERENCESvisitor_info
(user_id
))')
해결완료, 테스트중 visitor_info가 비어있는 상태로 INSERT문을 실행해서 생긴 결과임