Instead of commenting that you "are blocked" state actually happens I.e. What is the error message?
Based on the comment in your code I think this is the solution to your problem..
In whatever language you use, you have to make sure that the values referred to in foreign keys already exist on the other tables
You haven't given us any detail about your tables or data so this simple example will have to do..
Say you have two tables -
Car
which has columns
(id int, color int)
where
color
is a foreign key to ..
the
Color
table which has columns
(colorid int, description varchar(25))
.
For this example let's assume that both tables are completely empty.
This code will produce an error
INSERT INTO Car (id, color) VALUES (1,1);
INSERT INTO Color (id, description) VALUES (1, 'Blue');
because the row for 'Blue' with an Id of 1 does not exist in the
Color
table at the point in time where you are trying to reference it.
This code
will work
INSERT INTO Color (id, description) VALUES (1, 'Blue');
INSERT INTO Car (id, color) VALUES (1,1);
If you have more than one foreign key then all the values must already exist on their relevant table e.g.
INSERT INTO Color (id, description) VALUES (1, 'Blue');
INSERT INTO Make (id, maker) VALUES (1, 'Fiat');
INSERT INTO Car (id, color) VALUES (1,1);
not
INSERT INTO Car (id, color) VALUES (1,1);
INSERT INTO Color (id, description) VALUES (1, 'Blue');
INSERT INTO Make (id, maker) VALUES (1, 'Fiat');
You are also blindly inserting whatever is in the Excel worksheet into your database - what if two rows have
ville = 'Honfleur'
? If you have put a constraint on your table then this could be ther error you are getting.
You should be checking to see if the value already exists or use
INSERT IGNORE
or
REPLACE
or
INSERT .. ON DUPLICATE KEY UPDATE
(these are MySql specific, the concept is known as "UPSERT")