1
votes

I'd like to address question to those who use Mysql + Doctrine ORM + Doctrine migrations I have an association:

    /**
     * @var User
     *
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(nullable=true)
     */
    protected $sender;

(key point here is nullable=true. Some attributes are left behind intentionally)

  1. i do migraions:diff - generated migration with a piece sender_id VARCHAR(255) DEFAULT NULL
  2. run migrate
  3. then i do diff again, expecting no new migrations generated
  4. but no, i see new file with line CHANGE sender_id sender_id VARCHAR(255) DEFAULT NULL

It means that nothing is going to be changed, however doctrine dbal under Mysql driver doesn't see from entity annotations that DEFAULT NULL

I tried to add @ORM\Column(options={"default": NULL}).

That helped with preventing DEFAULT NULL in migrations, but FK and Index were dropped in this case.

Tried also add columnDefinition="VARCHAR(255) DEFAULT NULL" but also didn't work

How did you solve this issue?

1

1 Answers

0
votes

I had the same issue. In my case (Symfony, using Docker with the image "mariadb:10.5.8"), the solution was to set the correct server_version in the config:

doctrine:
    dbal:
        server_version: '5.7' # (this was previously incorrect in my setting!)

to

        server_version: 'mariadb-10.5.8' # (correct version for my setting, please adjust accordingly!)

Afer doing that and restarting Docker, the diff was empty ("No changes detected in your mapping information.").

All credit goes to the post of "tristanbes commented on Apr 4, 2018", see the following link:

https://github.com/doctrine/dbal/issues/2985