yii2常用的migrate命令

2021-09-24 10:17:03 字數 1676 閱讀 3655

開發中經常會用到的方法小結:

./yii migrate/create 表名

1、./yii migrate ***_xx

在表中插入某欄位 :

public function up()
修改表中某欄位:

public function up()
增加索引:

public function up()
建立資料表:

public function up()

$this->createtable('}', [

'id' => $this->primarykey(),

'parent_id' => $this->integer(11)->defaultvalue(0)->comment('父級選單id'),

'menu_name' => $this->string(100)->notnull()->comment('選單名稱'),

'menu_type' => $this->string(100)->notnull()->comment('選單型別(menu選單,sub_menu子選單)'),

'menu_action' => $this->string(100)->notnull()->comment('選單鏈結'),

'menu_roles' => $this->string(100)->comment('角色'),

'menu_depth' => $this->smallinteger(1)->defaultvalue(0)->comment('選單深度'),

'menu_icon' => $this->text()->comment('icon**:圖示'),

'menu_des' => $this->text()->comment('選單簡介'),

'menu_order' => $this->smallinteger(1)->defaultvalue(0)->comment('顯示順序'),

'menu_show' => $this->smallinteger(1)->defaultvalue(0)->comment('是否顯示(0:顯示, 1:不顯示)'),

'created_at' => $this->integer(),

'updated_at' => $this->integer(),

], $tableoptions);

}

刪除某欄位:

public function down()
刪除某張表:

public function down()

}');}

2/./yii migrate 預設執行 ./yii migrate/up 

./yii migrate/down 執行某些撤銷對錶的操作

./yii migratre/to (遷移檔名)執行某個指定的遷移檔案

在建立資料表的過程中可以同時聲稱多張表,刪除多張表

執行過的遷移檔案,會在資料庫的migration 中生成一條記錄,記錄此遷移檔案已經執行過,下次將執行資料表中不存在的遷移檔案

注意:./yii migrate/down 此命令執行不只刪除了對資料庫的操作同時也會刪除migration資料表中的執行記錄

yii2常用ActiveForm表單

表單整體輸出樣式 form activeform begin options enctype multipart form data class form horizontal method post template template n n colclass class col sm 3 con...

yii2 常用元件 表單

簡介 yii2中最常用的元件activeform,通過對activeform的靈活運用,能有效的提公升開發效率,所以這個是不得不說的乙個yii2元件,那麼下面就來了解一下yii2.0的activeform的具體用法 用法 form signup 文字框的標題 field model,test1 la...

yii2框架 yii2自身的自動載入 三

上一節說完了composer的自動載入,下面我們來說一下yii2自身的自動載入。在我們的入口檔案,例如index.php,如下 comment out the following two lines when deployed to production defined yii debug or d...