如何使用 yii 迁移将 a 列数据复制到 b 列

how to duplicate column a data to column b using yii migration

alter table user add column join_date datetime;
UPDATE user SET join_date = date_created;

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

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

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