I have a table with some fields and the first is my primary key, called token
.
I need that token isn't automatically, so, I want to set this value. For example,
$em = $this->getDoctrine()->getManager();
$object->setToken("first");
$object->setValue("123");
$em->persist($object);
$em->flush();
But, in my DB, always token is null
, why?
When I do flush, token value disappear.
In my entity, token is declared:
/**
* @var string
*
* @ORM\Column(name="token", type="string", length=45, nullable=false)
* @ORM\Id
*/
private $token;
/**
* Set token
*
* @param string $token
* @return Downloads
*/
public function setToken($token)
{
$this->token = $token;
return $this;
}
/**
* Get token
*
* @return string
*/
public function getToken()
{
return $this->token;
}
Try with ORM\GeneratedValue
/**
* @var string
*
* @ORM\Column(name="token", type="string", length=45, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
*/
private $token;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With