phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

type mapping mismatch: database can contain bool|null but property expects bool

Open AnjaLiebermann opened this issue 5 years ago • 3 comments

This is the error message I get using version 0.12.94:

  Line   src/Entity/Witness.php

  50     Property App\Entity\Witness::$charge type mapping mismatch: database can contain App\Entity\Charge|null but property expects
         App\Entity\Charge.
  61     Property App\Entity\Witness::$employee type mapping mismatch: database can contain bool|null but property expects bool.

This is my property definition:

    /**
     * This is the owning side.
     *
     * @ORM\ManyToOne(targetEntity="Charge", inversedBy="witnesses")
     * @ORM\JoinColumn(name="charge_id", referencedColumnName="id", nullable=false)
     */
    private Charge $charge;

    /**
     * @ORM\Column(name="employee", type="boolean", nullable=false)
     */
    private bool $employee = false;

And this is the part of the SQL statement generating my database: charge_id INT NOT NULL, gender VARCHAR(15) DEFAULT NULL, employee TINYINT(1) DEFAULT \'0\' NOT NULL,

As I see it the property employee isn't allowed to be null. It has the default value set. The doctrine notation forbids null values and the sql statemet geerating the table sets a default value and forbids null.

Where is the problem?

The same error is rised with the connected Entity "Charge".

See here the simplified version of my class, which is passing in the playground: https://phpstan.org/r/9a6a7486-75f9-490a-91e6-3ba5246b2d1d

AnjaLiebermann avatar Aug 16 '21 05:08 AnjaLiebermann

Hi, I'm scratching my head about this for the past 1,5 hours. I don't see why this should be reported. Please make sure that you clear your Doctrine metadata cache, and also clear PHPStan's result cache: https://phpstan.org/user-guide/result-cache#clearing-the-result-cache

If it's still reported even after these steps, please create a small reproducing repository that shows the same problem. Thanks.

ondrejmirtes avatar Aug 16 '21 07:08 ondrejmirtes

Thank you, that did in fact help!

AnjaLiebermann avatar Aug 16 '21 07:08 AnjaLiebermann

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Sep 17 '21 00:09 github-actions[bot]