Doctrine 在 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
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在添加排序规则后,实体如上所示。
<?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;
}
}
mysql -V
以查看Mariadb版本。 - Yoann Kergall