PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062

Today, we came across a problem with Drupal. Every time when we tries to add new contents, it is giving us the following error message

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062
Duplicate entry ‘0’ for key 2 INSERT INTO {node}…

At first, we thought it was some new modules that we have installed or enabled that might have caused this. We have spent a few days trying to troubleshoot this error and it turns out that there was a bad entry in the Drupal node table.
For some reason, there was a ‘0’ value on the ‘vid’ column. The value for this is usually the same as the ‘nid’ column. By fixing this, we have solved this error.

So from my understanding and from looking at the error message a little bit more, it does tell a lot of the problem.

1 – We know that it is a database problem. e.g SQLSTATE
2 – The problem occurs on key 2 when it tries to ‘insert’ data into the node table, which is the vid column in the node table in Drupal
3 – A duplicate entry ‘0’ tells us that the value ‘0’ is incorrect.