沃梦达 / 编程问答 / php问题 / 正文

Symfony 和 Doctrine 使迁移无效

Symfony and Doctrine making migration with no effect(Symfony 和 Doctrine 使迁移无效)

本文介绍了Symfony 和 Doctrine 使迁移无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Doctrine 正在 symfony 中生成迁移,并且在运行迁移之后没有任何变化,因此在下一个差异期间它是相同的.如何使 Doctrine 不产生这种迁移?手动运行 alter table 命令不会删除列排序规则.

bin/console 学说: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');

表格是这样的:

显示创建表会话;

<块引用>

创建表 会话 (sess_id varchar(128) 整理 utf8_unicode_ci 非空,sess_data longblob NOT NULL,sess_time int(11) NOT NULL,sess_lifetime int(11) NOT NULL,主键 (sess_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

实体是在添加如下排序规则之后

id;}/*** 获取 sessData** @return 字符串*/公共函数 getSessData(){返回 $this->sessData;}/*** 设置 sessData** @param 字符串 $sessData** @return 会话*/公共函数 setSessData($sessData){$this->sessData = $sessData;返回$这个;}/*** 获取会话时间** @return 整数*/公共函数 getSessTime(){返回 $this->sessTime;}/*** 设置会话时间** @param 整数 $sessTime** @return 会话*/公共函数 setSessTime($sessTime){$this->sessTime = $sessTime;返回$这个;}/*** 获取 sessLifetime** @return 整数*/公共函数 getSessLifetime(){return $this->sessLifetime;}/*** 设置 sessLifetime** @param 整数 $sessLifetime** @return 会话*/公共函数 setSessLifetime($sessLifetime){$this->sessLifetime = $sessLifetime;返回$这个;}}

解决方案

我遇到了类似的问题.

我用:

  • Symfony=3.4.9(弹性)
    • 教义/orm=^2.5.11
  • PHP=7.2.5
  • cURL=7.59.0
  • APCu=5.1.11
  • Xdebug=2.6.0
  • 作曲家=1.6.5
  • Nginx=1.14.0
  • MariaDB=10.2.14


解决办法:

为了纠正我的问题,commented OR set value 'mariadb-10.2.14' on property server_version in config/包/doctrine.yaml.


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

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 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;
    }
}

解决方案

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

这篇关于Symfony 和 Doctrine 使迁移无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Symfony 和 Doctrine 使迁移无效

基础教程推荐