MySQL: how to prevent deadlock on concurrent inserts
Both insert statements have the same values for the primary key which is why the deadlock occurred.

At the point of the deadlock, the other transaction could rollback. If the INSERT IGNORE did ignore, and the other transaction rolled back, then the definition of 'INSERT IGNORE' inserting if a record doesn't exist is violated.

This is why the deadlock is returned, because its a business logic problem that needs to be resolved by the application. The action to be taken in a deadlock depends on the situation that cannot be known upfront.