Doctrine schema:update generates the same SQL again and again

Viewed 1650

Running bin/console doctrine:schema:update --force again and again, it always output 39 queries executed even after clearing cache/restarting php-fpm. So it always execute the same SQL requests again and again...

The SQL looks likes (from --dump-sql)

ALTER TABLE apply_queue CHANGE cv_id cv_id INT DEFAULT NULL, CHANGE team_id team_id INT DEFAULT NULL;
....

And a lot of lines similar to this.

The ApplyQueue class look like:

/**
 * AppBundle\Entity\ApplyQueue.
 *
 * @ORM\Entity(repositoryClass="AppBundle\Entity\ApplyQueueRepository")
 * @ORM\Table(name="apply_queue")
 */
class ApplyQueue
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Cv")
     * @ORM\JoinColumn(name="cv_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $cv;

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Team")
     * @ORM\JoinColumn(name="team_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $team;

    ...

}

DBAL config :

doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
        types:
            json: Sonata\Doctrine\Types\JsonType
            review_status: AppBundle\Model\Enum\ReviewStatusEnumType
        mapping_types:
            review_status: string

The structure of the table:

enter image description here

This is an "old" project that has been upgraded to Symfony 3.4 and MariaDB 10.2.

Thanks

4 Answers

I had similar problem few weeks ago. In my case it was that after update --force it shows some column must be set not null on --dump-sql. Again and again. I don't remember so good what was problem but it was something like this:

I had for same column set to be null and to have default value. Without doctrine that could even work somehow, but doctrine expects tables to be designed good. What I want to say check your table. There is probably some error of this type. Goodluck!

check your database table type - i had a problem where the database type didnt support the feature doctrine trying to set.

Maybe run the sql on the database server and see if it 'works' / changes anything, then re-run

In your app/config/config.yml, check if doctrine cache is enabled as below :

doctrine:
    orm:
        metadata_cache_driver: redis

If so, you will have to flush redis cache:

php bin/console redis:flushdb --client=CLIENT_NAME -n
Related