0

我对 Doctrine Migrations 很陌生,如果这真的很明显,我很抱歉。

更新以提供更多信息

我有一个 Symfony2 实体映射如下:

/**
 * @ORM\Column(type="string")
 */
private $name;

这被添加到迁移中,并按照应有的方式进行部署。然后需要更新该列以接受空值,因此将其更改为:

/**
 * @ORM\Column(type="string", nullable=true)
 */
private $name;

问题是这对生成的迁移文件没有影响:

$ php app/console cache:clear
$ php app/console doctrine:migrations:diff
$ tail -50 app/DoctrineMigrations/Version20131028205742.php

<?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20131028205742 extends AbstractMigration
{
    public function up(Schema $schema)
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

    }

    public function down(Schema $schema)
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

    }
}

没有添加任何 ALTER 语句来处理空值。我可以删除并重建数据库,但由于已经部署了这个特定的迁移,这将导致生产数据库出现问题。我可以看到这种情况在未来再次发生,所以想多了解一点。

这是 Doctrine 和/或 Symfony2 Doctrine Migrations 捆绑包的限制吗?有没有办法在不编写自定义迁移的情况下解决这个问题?

请注意,我所有其他迁移工作正常,唯一的问题是向现有字段添加可为空的选项。

4

1 回答 1

3

Doctrine 的差异以这种方式工作,它将您的实体元数据与现有的数据库模式进行比较。因此,如果您在运行迁移doctrine:schema:update 运行 - 学说不会注意到任何变化,因为 db 架构已经更改(因此适合实体元数据)。基本上,在您运行迁移之后,您就不需要再运行update了。

于 2013-10-28T10:07:04.287 回答