Answer the question
In order to leave comments, you need to log in
Yii 2 migrations inserting multiple rows?
how can i insert multiple rows and delete also a few
public function safeUp()
{
$this->insert('country', [
'name' => 'Австралия',
'name' => 'Австрия',
'name' => 'Азербайджан',
'name' => 'Албания',
]);
}
public function safeDown()
{
$this->delete('country', [
'name' => 'Австралия',
'name' => 'Австрия',
'name' => 'Азербайджан',
'name' => 'Албания',
]);
}
Answer the question
In order to leave comments, you need to log in
<?php
use yii\db\Migration;
class m160322_045630_add_catalog_data extends Migration {
public function safeUp()
{
Yii::$app->db->createCommand()->batchInsert('country', ['name'], [
['Австралия'],
['Австрия'],
['Азербайджан'],
['Албания'],
])->execute();
}
public function safeDown()
{
Yii::$app->db->createCommand()->delete('country', ['in', 'name', ['Австралия', 'Австрия', 'Азербайджан', 'Албания']]
)->execute();
}
batchInsert()
public function up()
{
$this->batchInsert('country', ['name'], [
['Австралия'],
[ 'Австрия'],
['Азербайджан'],
[ 'Албания'],
]);
}
public function down()
{
$this->delete('country', ['in', 'name', [
'Австралия',
'Австрия',
'Азербайджан',
'Албания',
]]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question