symfony2 doctrine allow null values?

后端 未结 2 494
一整个雨季
一整个雨季 2021-01-01 08:32

So, I\'m still REALLY new to symfony but i\'m learning quickly... I created an entity and a crud (i forget how I did it actually but it was via the command line)..

相关标签:
2条回答
  • 2021-01-01 09:16

    Set your default values directly in the entity file:

    /**
     * @var varchar $totaltime
     */
    private $totaltime = null;
    

    Then add to your yml file:

        totaltime:
            type: string
            nullable: TRUE
    

    Then something like:

    php app/console doctrine:schema:update --dump-sql
    

    To update the database.

    However, you really need to slow down and work you way through the examples in the manual. Guessing at how you did things is really not going to get you very far.

    0 讨论(0)
  • 2021-01-01 09:28

    I've just been looking for the solution, and wasn't happy with the accepted solution. [Edit: though I now know it's because I was using annotation]. The way I've found that works for me is setting nullable:

    /**
     * @ORM\Column(type="varchar", nullable=true)
     */
    private $totaltime = null;
    
    0 讨论(0)
提交回复
热议问题