开发中经常会用到的方法小结:
1、./yii migrate/create 文件名
创建表:
$this->createTable(‘mtg_user’, [
‘id’ => $this->primaryKey()->comment(‘用户ID’),
‘project_id’ => $this->integer(11)->notNull()->comment(‘项目’),
‘username’ => $this->string(50)->notNull()->comment(‘登录账号’),
‘password’ => $this->string(50)->notNull()->comment(‘登录密码’),
‘role_id’ => $this->integer(11)->null()->comment(‘角色ID’),
‘realname’ => $this->string(50)->notNull()->comment(‘姓名’),
‘mobile’ => $this->string(11)->comment(‘手机号’),
‘bank_card’ => $this->string(50)->comment(‘银行卡号’),
‘email’ => $this->string(50)->comment(‘邮箱’),
‘idsn’ => $this->string(50)->comment(‘身份证号’),
‘wechat_user_id’ => $this->integer(11)->comment(‘微信用户ID’),
‘admin_id’ => $this->integer(11)->comment(‘添加人ID’),
‘price’ => $this->decimal(10,2)->notNull()->comment(‘费用’),
‘is_enabled’ => $this->tinyInteger(1)->defaultValue(1)->comment(‘是否启用’),
‘deleted’ => $this->tinyInteger(1)->defaultValue(0)->comment(‘是否删除’),
‘created_at’ => $this->dateTime()->comment(‘创建时间’),
‘updated_at’ => $this->dateTime()->comment(‘修改时间’),
‘content’ => $this->text()->null()->comment(‘协议内容’),
], ‘comment “会议用户”’);
修改表名
$this->renameTable(‘study_rename_table’,‘study_rename_table1’);
删除表
$this->dropTable(‘study_rename_table1’);
新增字段
$this−>addColumn(′user′,′testcolumn′,this->addColumn('user','test_column',this−>addColumn(′user′,′testcolumn′,this->text()->comment(‘测试字段’)->after(‘is_bank_card_belong’));
修改字段
$this−>alterColumn(′user′,′testcolumn′,this->alterColumn('user','test_column',this−>alterColumn(′user′,′testcolumn′,this->string(255)->comment(‘test_edit_column’));
修改字段属性
$this->renameColumn(‘mtg_meeting_docent’,‘service_charge_id’,‘docent_position_cost_id’);
修改字段名
$this->renameColumn(‘user’,‘test_column’,‘test_edit_column’);
删除字段
$this->dropColumn(‘user’,‘test_edit_column’);
创建索引
$this->createIndex(‘mobile_index’,‘user’,‘mobile’,True);
删除索引
$this->dropIndex(‘mobile_index’,‘user’);
给字段添加备注
$this->addCommentOnColumn(‘website_user’,‘retry_times’,‘重试次数’);
字段删除备注
$this->dropCommentFromColumn(‘website_user’,‘retry_times’);
给表添加备注
$this->addCommentOnTable(‘user_making_attach’,‘用户基本材料存储表’);
表删除备注
$this->dropCommentFromTable(‘user_making_attach’);