Symfony and Doctrine making migration with no effect

笑着哭i 提交于 2020-01-13 09:59:06

问题


Doctrine is generating migration in symfony and nothing changes afer running the migration so during next diff it is the same. How to make Doctrine not generate this migration? Running the alter table command manually does not remove column collation.

bin/console doctrine:migration:diff

up

$this->addSql('ALTER TABLE session CHANGE sess_id sess_id VARCHAR(128) NOT NULL');

down

$this->addSql('ALTER TABLE session CHANGE sess_id sess_id VARCHAR(128) NOT NULL COLLATE utf8_unicode_ci');

Table looks like that:

show create table session;    

CREATE TABLE session ( sess_id varchar(128) COLLATE utf8_unicode_ci NOT NULL, sess_data longblob NOT NULL, sess_time int(11) NOT NULL, sess_lifetime int(11) NOT NULL, PRIMARY KEY (sess_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

Entity is after adding collation like below

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Session
 *
 * @ORM\Table(name="session")
 * @ORM\Entity(repositoryClass="App\Repository\SessionRepository")
 */
class Session
{
    /**
     * @var string
     *
     * @ORM\Column(name="sess_id", type="string", length=128, options={"collation":"utf8_unicode_ci"})
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="sess_data", type="blob")
     */
    private $sessData;

    /**
     * @var int
     *
     * @ORM\Column(name="sess_time", type="integer")
     */
    private $sessTime;

    /**
     * @var int
     *
     * @ORM\Column(name="sess_lifetime", type="integer")
     */
    private $sessLifetime;


    /**
     * Get id
     *
     * @return string
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get sessData
     *
     * @return string
     */
    public function getSessData()
    {
        return $this->sessData;
    }

    /**
     * Set sessData
     *
     * @param string $sessData
     *
     * @return Session
     */
    public function setSessData($sessData)
    {
        $this->sessData = $sessData;

        return $this;
    }

    /**
     * Get sessTime
     *
     * @return int
     */
    public function getSessTime()
    {
        return $this->sessTime;
    }

    /**
     * Set sessTime
     *
     * @param integer $sessTime
     *
     * @return Session
     */
    public function setSessTime($sessTime)
    {
        $this->sessTime = $sessTime;

        return $this;
    }

    /**
     * Get sessLifetime
     *
     * @return int
     */
    public function getSessLifetime()
    {
        return $this->sessLifetime;
    }

    /**
     * Set sessLifetime
     *
     * @param integer $sessLifetime
     *
     * @return Session
     */
    public function setSessLifetime($sessLifetime)
    {
        $this->sessLifetime = $sessLifetime;

        return $this;
    }
}

回答1:


I had a similar problem.

I use :

  • Symfony=3.4.9 (flex)
    • doctrine/orm=^2.5.11
  • PHP=7.2.5
  • cURL=7.59.0
  • APCu=5.1.11
  • Xdebug=2.6.0
  • Composer=1.6.5
  • Nginx=1.14.0
  • MariaDB=10.2.14


Solution :

For correct my problem, commented OR set value 'mariadb-10.2.14' on the property server_version in config/packages/doctrine.yaml.


Highly inspired by : https://github.com/doctrine/dbal/issues/2985




回答2:


Try to add this to column annotation:

/**
 * @var string
 *
 * @ORM\Column(options={"collation":"utf8_unicode_ci"})
 */
private $sess_id;


来源:https://stackoverflow.com/questions/48909114/symfony-and-doctrine-making-migration-with-no-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!