yii2 migrate 数据库迁移的简单分享
生活随笔
收集整理的這篇文章主要介紹了
yii2 migrate 数据库迁移的简单分享
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
開發中經常會用到的方法小結:
1、./yii migrate xxx_xx 在表中插入某字段 :
public function up(){$this->addColumn('{{application_service}}', 'auditor', 'INT(10) NOT NULL COMMENT "審核人" AFTER 'user_id', CHANGE COLUMN `status` `status` tinyint(4) NOT NULL COMMENT "綁定狀態,0:解綁 1:綁定" AFTER 'auditor''); }
2.?修改表中某字段:
public function up(){$this->alterColumn('{{application_service}}', 'status', 'SMALLINT(4) NOT NULL DEFAULT 0 COMMENT "綁定狀態,0:解綁 1:未綁定 2:審核中 3:審核通過 4:審核拒絕 5:禁用"'); }
增加索引:
public function up(){$this->createIndex('created_at', "{{app_base}}", ['created_at'],true); }
創建數據表:
public function up() {$tableOptions = null;if ($this->db->driverName === 'mysql') {$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB COMMENT="菜單表"';}$this->createTable('{{%menu}}', ['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(){$this->dropColumn('{{app_base}}', 'manager_id');}
刪除某張表:
public function down(){$this->dropTable('{{%file_storage_item}}'); }
2/./yii migrate 默認執行 ./yii migrate/up?
./yii migrate/down 執行某些撤銷對表的操作 ./yii migratre/to (遷移文件名)執行某個指定的遷移文件 在創建數據表的過程中可以同時聲稱多張表,刪除多張表 執行過的遷移文件,會在數據庫的migration 中生成一條記錄,記錄此遷移文件已經執行過,下次將執行數據表中不存在的遷移文件 注意: ./yii migrate/down 此命令執行不只刪除了對數據庫的操作同時也會刪除migration數據表中的執行記錄
?
轉載于:https://www.cnblogs.com/echojson/p/10895232.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的yii2 migrate 数据库迁移的简单分享的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 47.QT-QChart之曲线图,饼状图
- 下一篇: Python与MySQL连接