I’m trying to create a migration that changes the records I need in a table
$sql = '';
$sql .= "UPDATE card_series SET Code = 903 WHERE ID = 1600;";
$cardsSeries1600 = CardList::find()
->where(['seriesId' => 1600])
->orderBy('ID')
->all();
$cardNum = 2;
foreach ($cardsSeries1600 as $card) {
$number = str_pad($cardNum, 8, "0", STR_PAD_LEFT);
$cardId = (1903).$number;
$sql .= "UPDATE card_list SET ID = ".$cardId.", Code = '903', Number = '".$number."' WHERE ID = ".$card->ID.";";
$cardNum++;
}
$this->execute($sql);
But in the end, my migration works in such a way that at first all my necessary records change, but then immediately they change to even newer ones, here is an example
UPDATE card_series SET Code = 903 WHERE ID = 1600;UPDATE card_list SET ID = 190300000002, Code = ‘903’, Number = ‘00000002’ WHERE ID = 1111000005;UPDATE card_list SET ID = 190300000003, Code = ‘903’, Number = ‘00000003’ WHERE ID = 1111000011;UPDATE card_list SET ID = 190300000004, Code = ‘903’, Number = ‘00000004’ WHERE ID = 190300000002;UPDATE card_list SET ID = 190300000005, Code = ‘903’, Number = ‘00000005’ WHERE ID = 190300000003;
How can this be fixed?
2
Answers
Can you explain what effect you expect? It seems to be doing what you programmed.
Where is the problem?
Can try like below ?