I am trying to input data from a file into my sql table and am getting this erro
ID: 3776620 • Letter: I
Question
I am trying to input data from a file into my sql table and am getting this error. cannot add or update a child row a foreign key constraint fails.
INPUT FILE IS:
team_id pennants worldseries
1 1 1
2 17 3
3 7 26
4 12 7
5 16 2
6 6 3
7 10 5
8 5 2
9 1 0
10 10 4
11 2 2
12 1 0
13 2 1
14 1 1
15 22 6
16 1 0
17 6 3
18 4 2
19 39 26
20 15 9
21 6 2
22 9 5
23 2 0
24 20 5
25 0 0
26 21 10
27 1 0
28 0 0
29 2 2
30 0 0
Table Code is :
CREATE TABLE champs(
champ_id MEDIUMINT UNSIGNED NOT NULL,
team_id MEDIUMINT UNSIGNED NOT NULL,
pennants MEDIUMINT UNSIGNED NOT NULL,
worldseries MEDIUMINT UNSIGNED NOT NULL,
PRIMARY KEY (champ_id),
FOREIGN KEY (team_id) REFERENCES teamstats(team_id),
INDEX team_index (team_id)
);
Explanation / Answer
Your error "cannot add or update a child row a foreign key constraint fails" means that you are trying to add the value to a Foreign key field , and that valu is not present in the primary key field of the parent table.
Which means the team_id column of the table teamstats does not contain tone of the value you are trying to insert in to team_id of current table.
So try checking the values of team_id in the teamstats.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.