Temporarily disable the foreign key constraint (ALTER TABLE xxx DROP CONSTRAINT fkname), do the import, then use a query or queries to find the problem, fix the data, re-establish the foreign key.
Finding the bad field shouldn't be hard.
Let's say you had table
CREATE TABLE users (
userid INT PRIMARY KEY,
CREATE TABLE postings (
postid INT PRIMARY KEY,
CONSTRAINT posting_user_fk FOREIGN KEY (postedby) REFERENCE users(userid),
And when you import some data into the postings
table you get a foreign key error.
So you drop the foreign key
ALTER TABLE postings DROP FOREIGN KEY posting_user_fk
, do the import, and then do something like:
FROM postings AS P LEFT JOIN users AS U ON P.postedby = U.userid
WHERE U.userid IS NULL
Presto. That finds all the records with problems, and then you can go in and fix just those records (or delete them). When they are all fixed, re-create the FOREIGN KEY.