Home > Software engineering >  symfony doctrine will not default a boolean to 0
symfony doctrine will not default a boolean to 0

Time:09-01

I have tried in several ways to have symfony default a boolean to 0 rather than null (as null gives me a database level error upon flush).

An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'auto_created' cannot be null

This made no difference:

/**
 * @ORM\Column(type="boolean", options={"default":"0"})
 */
private $autoCreated;  

Some logic i the setter made no difference either

public function setAutoCreated(bool $autoCreated): self
{
    if is_null($autoCreated) {
        $autoCreated = 0;
    }

    $this->autoCreated = $autoCreated;

    return $this;
}  

As well as

public function setAutoCreated(bool $autoCreated): self
{
    if is_null($autoCreated) {
        $autoCreated = false;
    }

    $this->autoCreated = $autoCreated;

    return $this;
}  

Database looks like this

phpmyadmin saying default:0

I am clearly missing something...?

Sure I can do a simple $user->setAutoCreated(false); everywhere I create this entity, but I don't get why I should have to

  • Related