How to solve the error while uploading image to nodes?
Try the Upload QC module. Some details about it (from its project page):

This module offers checks and validations for the process of uploading files. It extends the Drupal 7 core and helps avoid errors during file upload. You can now say good bye to PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed}.
WHO SHOULD USE
This module is for you if:

you run into errors like this one PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed} OR PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ... for key 'uri': INSERT INTO {file_managed}.

you would like to add additional file upload validations that check for (a) file name length, (b) file name containing certain words/characters, (c) file name not containing certain words/characters.

Drupal and/or PHP upload size limit is not working for you and you would like to set it yourself in your admin section.



Looks like item &quot;1.&quot; is pretty close to your issue, no?