【发布时间】:2020-07-27 21:04:49
【问题描述】:
我为 cookbook 的实体 Command 的属性 type 做了一个特殊的 ENUM 类型。
该属性如下所示:
/**
* @var CommandType
*
* @ORM\Column(type="command_type")
*/
protected $type;
这个 sn-p 描述了新的学说类型:
final class CommandTypeType extends EnumerableType
{
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'VARCHAR(30)';
}
public function getName(): string
{
return 'command_type';
}
protected function getClassName(): string
{
return CommandType::class;
}
}
在第一次为实体运行命令 /bin/console doctrine:migrations:diff 后,我得到了迁移,它看起来是正确的
final class Version2020 072720500 extends AbstractMigration
{
public function up(Schema $schema) : void
{
$this->addSql("CREATE TABLE commands (
id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(30) DEFAULT NULL,
command VARCHAR(100) DEFAULT NULL,
type varchar(30) NOT NULL,
PRIMARY KEY(id)
) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB");
}
public function down(Schema $schema) : void
{
$this->addSql('DROP TABLE commands');
}
}
下一步是运行命令/bin/console doctrine:migrations:migrate,它工作正常,表已创建。
然后我再次运行命令/bin/console doctrine:migrations:diff 并获得新的迁移
final class Version20200727205035 extends AbstractMigration
{
public function up(Schema $schema) : void
{
$this->addSql('ALTER TABLE commands CHANGE type type VARCHAR(30) NOT NULL');
}
public function down(Schema $schema) : void
{
$this->addSql('ALTER TABLE commands CHANGE type type VARCHAR(30) CHARACTER SET utf8 NOT NULL COLLATE `utf8_unicode_ci`');
}
}
我不知道为什么第二个差异会产生这种奇怪的迁移。
我做错了什么?
- Symfony 4.4
- doctrine/doctrine-migrations-bundle 3.0.1
- 学说/迁移 3.0.1
【问题讨论】:
标签: symfony doctrine-orm doctrine