K
K
knowledge2018-07-20 11:36:36
Yii
knowledge, 2018-07-20 11:36:36

How to copy the values ​​of one column to another in yii2 during migration?

there is a table with fields id, user email, birth_of_date
string birth_of_date in integer, I need to store dates in date I
create a new column during migration

$this->addColumn('table_name', 'new_birth_of_date', $this->date()->after('birth_of_date'));

trying to translate data with conversion
$this->update('table_name', ['new_birth_of_date' => 'FROM_UNIXTIME(birth_of_date)']);

but it reads 'FROM_UNIXTIME(birth_of_date)' as a string
if I just write 'birth_of_date' same
how do I copy values ​​from one column to another in migration?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-07-20
@knowledge

$this->update('table_name', ['new_birth_of_date' => new Expression('FROM_UNIXTIME()')]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question