生成的ID始终为0

时间:2017-09-08 14:44:36

标签: php doctrine-orm

我已经宣布了我的实体的身份证明:

 /**
 * @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
 */
 protected $id;

但每当我尝试在表单后保存我的数据库时,我得到'0',因此给出:Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'

我的存储逻辑如下:

public function CallManager($data) 
    {
    $callRequested= new CallRequested;
    $callRequested-> setClientContact($data['clientContact']);
    $callRequested-> setProvider($data['provider']);
    $callRequested-> setCallCenter($data['callCenterContact']);
    $whenCall= $data['schedule'];
    $language= $data['language'];
    $date = new \DateTime();
    $callRequested-> setRequestTime($date);

    var_dump($data);

    $this->entityManager->persist($callRequested);
    $this->entityManager->flush();

    }

我该怎么办?

1 个答案:

答案 0 :(得分:1)

你需要告诉它你希望它像这样自动增加:

/**
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 * @ORM\Column(type="integer")
 */
private $id;