publicfunctionactionDown(){$model= \Yii::$app->db->createCommand("select table_name from information_schema.tables where table_schema='这里配置数据库名称' and table_type='base table'");$posts=$model->queryAll();foreach($postsas$key=>$item){$sql="show create table ".$item['table_name']." ";$keys= \Yii::$app->db->createCommand($sql);$keyposts=$keys->queryOne();$num=(string)(52200+$key);$str='m191210_0'.$num.'_create_'.$item['table_name'].'.php';$myfile=fopen($str,"w")ordie("Unable to open file!");$txt="<?php
use yii\db\Migration;
class ".'m190310_0'.$num.'_create_'.$item['table_name']." extends Migration
{
public function safeUp()
{
".'$this->execute('."\"".$keyposts['Create Table']."\");
}
public function safeDown()
{
".'$this->dropTable('."'".$item['table_name']."');
}
}
";fwrite($myfile,$txt);fclose($myfile);}print_r('success');}