Answer the question
In order to leave comments, you need to log in
How to iterate over all rows in a table in migration?
The bottom line is that in the migration you need to go through all the lines and change one field in each line. But I can’t find something how they move in migration to make such a massive update
Answer the question
In order to leave comments, you need to log in
I'm not sure if this is the best option, but you can always use the ActiveRecord model for this - for example, if you need to update the 'status' field in the 'records' table:
public function safeUp()
{
$modelsQuery = Record::find();
/** @var Record $record */
foreach ($modelsQuery->each() as $record) {
$record->status = 'new status';
$record->save();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question