【问题标题】:how to duplicate column a data to column b using yii migration如何使用 yii 迁移将 a 列数据复制到 b 列
【发布时间】:2016-08-30 09:47:51
【问题描述】:
alter table user add column join_date datetime;
UPDATE user SET join_date = date_created;

通过使用上面的代码,我可以向表中添加一个新列,并将 join_date 列设置为与创建日期中的数据相同。如何使用 yii2 迁移执行此操作?

【问题讨论】:

    标签: php mysql yii yii2 yii-migrations


    【解决方案1】:

    只需在 up() 函数中添加两个条目

    $this->addColumn('user', 'join_date', $this->dateTime());
    $this->execute('update user set join_date = date_created;');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-20
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多