代码之家  ›  专栏  ›  技术社区  ›  conradkleinespel

如何防止条令删除计算/生成列

  •  1
  • conradkleinespel  · 技术社区  · 7 年前

    我将mariadb用于symfony项目,并设置了一个计算列,其中包含:

    ALTER TABLE history_event ADD quote_status_change SMALLINT AS (JSON_VALUE(payload, '$.change_set.status[1]'));
    

    当我与 bin/console doctrine:schema:update ,将删除计算列,可能是因为它在 HistoryEvent 实体类。

    如何在运行迁移时防止Doctrine删除计算列?

    2 回复  |  直到 7 年前
        1
  •  0
  •   malarzm    7 年前

    恐怕您可能运气不好,有一个开放功能请求,但尚未实现: https://github.com/doctrine/doctrine2/issues/6434

        2
  •  1
  •   Eugene Ananin    6 年前

    我在第2.10条中用 OnSchemaColumnDefinition Event 。我的代码看起来像这样:

    public function onSchemaColumnDefinition(SchemaColumnDefinitionEventArgs $eventArgs)
    {
        if ($eventArgs->getTable() === 'my_table') {
            if (!in_array($eventArgs->getTableColumn()['field'], ['id', 'column_1', 'column_2'])) {
                $eventArgs->preventDefault();
            }
        }
    }
    

    在我的例子中,我使用symfony 4.2,所以我设置了事件侦听器类 as per .