laravel migrate增加、修改、删除字段

生成migration文件

 1 php artisan make:migration alter_xxx_table 

修改migration文件

 1     public function up()
 2     {
 3         Schema::table('xxx', function (Blueprint $table) {
 4             $table->string('a', 1000); //增加
 5             $table->string('b', 100)->nullable()->change(); //修改
 6             $table->renameColumn('c', 'd'); //重命名
 7             $table->dropColumn(['e', 'f', 'g']);//删除
 8         });
 9     }
10 
11     /**
12      * Reverse the migrations.
13      *
14      * @return void
15      */
16     public function down()
17     {
18         Schema::table('xxx', function (Blueprint $table) {
19             $table->drop_column('a'); //增加
20             $table->string('b', 100)->change(); //修改
21             $table->renameColumn('d', 'c'); //重命名
22             $table->string('e', 1000); //删除
23             $table->string('f', 1000); //删除
24             $table->string('g', 1000); //删除
25         });
26     }
27 }

执行命令

 1 php artisan migrate 

撤回命令

 1 php artisan migrate:rollback --step=n(n为撤回步数) 

 

posted @ 2020-06-19 22:46  Helix006  阅读(2968)  评论(0编辑  收藏  举报