zoukankan      html  css  js  c++  java
  • 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为撤回步数) 

  • 相关阅读:
    162. Find Peak Element
    475. Heaters
    字符串统计
    数据的交换输出
    偶数求和
    青年歌手大奖赛_评委会打分
    蟠桃记
    素数判定
    多项式求和
    出现Presentation Error的解决方法
  • 原文地址:https://www.cnblogs.com/VRGamer-006/p/13166810.html
Copyright © 2011-2022 走看看