2017-10-17 58 views
-1

我用Google搜索和所有答案似乎使用查詢生成器建議 - 但我寧願這個值通過實體API設置爲NULL(即:setUsername(空))。將Doctrine實體值設置爲NULL?

這樣做但是將該值設置爲空字符串不是NULL。

有什麼辦法來實現這一目標,而不訴諸實施一個UPDATE查詢?

編輯

$em = $this->getDoctrine()->getManager(); 
$quote = $em->getRepository('AppBundle:Quote')->findOneByUuid($uuid); 
if (null !== $quote) { 
    $quote->setUuid(null); // *** SET EMPTY STRING NOT RDBMS NULL *** 

    $em->persist($quote); 
    $em->flush(); 

    return $this->render('quote/thanks.html.twig'); 
} 

實體

/** 
* @ORM\Column(type="string", unique=true, length=36, nullable=false) 
*/ 
private $uuid; 
+0

什麼 「這個值」?這個問題目前還不清楚。添加更多相關細節。 – svgrafov

+2

在數據庫中,如果該列的默認值設置爲空字符串,並正在從理論設定值設置爲null,將其值設置爲空字符串不是null –

+0

顯示的'username'字段定義(教義註釋)。 – miikes

回答

0

在數據庫中,如果該列的默認值設置爲空字符串,並正在從學說爲null,它將設置值設定值空字符串不是null

1

你應該在你的實體設置爲空的,以true

@ORM\Column(type="string", unique=true, length=36, nullable=true) 
private $uuid; 

之後,你應該用這個學說命令:

php bin/console doctrine:schema:update --force 
相關問題