我正在尝试将外键添加到表table2
中table1
。但是我遇到了这样的错误...问题是什么...帮助
Error
SQL query:
ALTER TABLE `table2` ADD FOREIGN KEY ( `bus_id` ) REFERENCES `db1`.`table1` (
`bus_id`
) ON DELETE CASCADE ON UPDATE CASCADE ;
MySQL said: Documentation
#1452 - Cannot add or update a child row: a foreign key constraint fails (`db1`.`#sql-664_e2`, CONSTRAINT `#sql-664_e2_ibfk_1` FOREIGN KEY (`bus_id`) REFERENCES `table1` (`bus_id`) ON DELETE CASCADE ON UPDATE CASCADE)
表1的结构
表2的结构