Symfony和Doctrine使迁移无效

Docfine正在symfony中生成迁移,并且在迁移迁移时没有任何更改,因此在下次比较时它是相同的。 如何使Doctrine不会产生这种迁移? 手动运行alter table命令不会删除列归类。

bin/console doctrine:migration:diff

向上

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

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

表格如下所示:

show create table session;    

CREATE TABLE sessionsess_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

实体在添加如下所示的整理之后

<?php

namespace AppEntity;

use DoctrineORMMapping as ORM;

/**
 * Session
 *
 * @ORMTable(name="session")
 * @ORMEntity(repositoryClass="AppRepositorySessionRepository")
 */
class Session
{
    /**
     * @var string
     *
     * @ORMColumn(name="sess_id", type="string", length=128, options={"collation":"utf8_unicode_ci"})
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    private $id;

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

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

    /**
     * @var int
     *
     * @ORMColumn(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;
    }
}

尝试将其添加到列注释中:

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

我有类似的问题。

我用 :

  • Symfony = 3.4.9(flex)
  • 教义/ ORM = ^ 2.5.11
  • PHP = 7.2.5
  • 卷曲= 7.59.0
  • APCu = 5.1.11
  • Xdebug的= 2.6.0
  • 作曲家= 1.6.5
  • Nginx的= 1.14.0
  • MariaDB = 10.2.14

  • 解答:

    为了纠正我的问题,请在config/packages/doctrine.yaml的属性server_version注释或设置值'mariadb-10.2.14'


    高度启发:https://github.com/doctrine/dbal/issues/2985

    链接地址: http://www.djcxy.com/p/68783.html

    上一篇: Symfony and Doctrine making migration with no effect

    下一篇: MySQL Limit LEFT JOIN Subquery after joining