我对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捆绑包的限制吗?有没有办法在不编写自定义迁移的情况下解决这个问题?
请注意,我的所有其他迁移工作正常,唯一的问题是在现有字段中添加可空选项。
答案 0 :(得分:3)
Doctrine的diff以这种方式工作,它将您的实体元数据与现有数据库模式进行比较。因此,如果您在之后运行doctrine:schema:update
,那么您已经运行了迁移 - doctrine没有注意到任何更改,因为db schema已经更改(因此适合于引入元数据)。基本上,在您运行迁移之后,您不再需要运行update
。