Use COALESCE
to change the null result of the subquery to a default value.
INSERT INTO illustrations (path, date_creation, id_exercise, position)
VALUES (
"2789c0bdda6981fadd87c30af74dfc5d.jpg",
"1384104485",
"4",
COALESCE((SELECT COUNT(I.id)
FROM illustrations I
WHERE I.id_exercise = 4
), 0)
)
Also the GROUP BY
was unnecessary.