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為撤回步數) 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM