gpt4 book ai didi

php - 学说迁移 : altering a column to be nullable in production

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:38 25 4
gpt4 key购买 nike

我对 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 迁移包的限制吗?有没有办法在不编写自定义迁移的情况下解决这个问题?

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

最佳答案

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

关于php - 学说迁移 : altering a column to be nullable in production,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19631664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com