Tag Archives: 2147483647

Doctrine ORM: Exception “Duplicate entry ‘2147483647’”

I was storing Facebook and Twitter profile IDs and I got this error:

  [Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2147
  483647' for key 'PRIMARY'

  [PDOException]
  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2147
  483647' for key 'PRIMARY'

When I went back to my data there was no ID with 2147483647 value. Then I realized that 2147483647 is the maximun value you can store in MySQL with a Doctrine integer type. So I just changed integer to bigint in my entities and the problem was solved.

class TwitterProfile
{
    /**
     * @ORM\Id
     * @ORM\Column(type="bigint")
     */
    protected $id;
    ...
}

doctrine-mysql-duplicate-entry-2147483647