IvanCloud IvanCloud - 1 year ago 113
MySQL Question

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;

By using the code above, I am able to add a new column to the table and set join_date column to have same data as those in date created. How can i perform this action using yii2 migration?

Answer Source

Just add it a two entries in your up() function

$this->addColumn('user', 'join_date', $this->dateTime());
$this->execute('update user set join_date = date_created;');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download