2013-10-28 113 views
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捆绑的限制吗?有没有办法解决这个问题,而无需编写自定义迁移?

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

+0

您是否在生成差异前清除了缓存**?我认为这应该始终是问题出现时的第一个问题:D – nifr

+0

是的,我清除了缓存。我不会认为这是我的问题的路线,虽然其他实体更新通过罚款,而不是ALTER声明为空。 –

+0

你是什么意思由'产生的差异文件'? –

回答

3

Doctrine的差异是这样工作的,它将你的实体元数据与现有的数据库模式进行比较。因此,如果在之后运行doctrine:schema:update,则已经运行迁移 - 原则没有注意到任何更改,因为数据库模式已更改(因此适用于实现元数据)。基本上,在你运行迁移后,你不需要再运行update

+0

感谢您的回答,我没有重建数据库,我认为我只会使用diff和migrate命令,但在回滚一下之后,按照您的步骤进行操作。我猜在某些时候我必须以错误的顺序运行命令并搞砸了。 –