Need a better way to insert non-existent values in referenced table during insert/update in referencing one
Instead of trying to insert directly into the ball table you could insert your data into a temporary newdata table ...



CREATE TEMPORARY TABLE newdata (
    name VARCHAR(255),
    colorname VARCHAR(255)
    );

INSERT INTO newdata (name, colorname) VALUES 
    ('Big Yellow Ball', 'yellow'),
    ('Small Purple Ball', 'purple');


... then perform an INSERT INTO color to create entries for any color names that don't already exist ...

INSERT INTO color (name)
SELECT colorname FROM newdata
WHERE colorname NOT IN (SELECT name FROM color);


... and then INSERT INTO ball with

INSERT INTO ball (name, color)
SELECT newdata.name, color.id
FROM newdata INNER JOIN color ON newdata.colorname = color.name;