增加学生的自定义考号

This commit is contained in:
东宝书记 committed 2021-05-25 20:04:15 +08:00
1 parent 175121d28a
commit bfd05b4a66
5 files changed
+75 -8

No files matched your search

@@ -47,6 +47,7 @@ class Student extends Migrator
->addColumn('kaoshi','boolean',['limit'=>1,'default'=>1,'null'=>false,'comment'=>'是否参加考试'])
->addColumn('quanpin','string',['limit'=>30,'default'=>'a','null'=>false,'comment'=>'全拼'])
->addColumn('shoupin','string',['limit'=>5,'default'=>'a','null'=>false,'comment'=>'简拼'])
->addColumn('kaohao','string',['limit'=>25,'null'=>true,'comment'=>'自定义考号'])
->addColumn('create_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'创建时间'])
->addColumn('update_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'更新时间'])
->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间'])
@@ -0,0 +1,51 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class AddStudentKaohao extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function up()
{
$table = $this->table('student');
$column = $table->hasColumn('kaohao');
if (!$column) {
$table
->addColumn('kaohao','string',['limit'=>25,'null'=>true,'comment'=>'自定义考号'])
->update();
}
}
//版本退回
public function down()
{
$table = $this->table('student');
$column = $table->hasColumn('kaohao');
if ($column) {
$table
->removeColumn('kaohao');
}
}
}