zoukankan      html  css  js  c++  java
  • laraval migration 新增字段或者修改字段的方法

    1.进入项目根目录执行artisan命令生成migration文件,可以指定--table和--path参数,会在对应目录下生成migration文件。

    php artisan make:migration alter_table_his_decisions  --table=his_decisions --path=database/migrations/ca/

    2.在migration文件中的up方法中新增或者修改字段

        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::table('his_decisions', function (Blueprint $table) {
                $table->string('primary_refuse_reason')->default('')->comment('拒绝主原因');
                $table->string('secondary_refuse_reason')->default('')->comment('拒绝子原因');
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::table('his_decisions', function (Blueprint $table) {
                $table->drop_column('primary_refuse_reason');
                $table->drop_column('secondary_refuse_reason');
            });
        }

    3.执行artisan命令来使变更生效,可以指定path参数到目录级别

    php artisan migrate --path=database/migrations/ca/ 

    ps:

    一个很好用的参数来查看artisan命令可以跟哪些参数,比如想知道迁移命令后接的参数

    php artisan migrate --help
  • 相关阅读:
    while练习题
    流程控制之for循环
    流程控制之while循环
    流程控制之if判断
    作业
    基本运算符
    输入输出
    基本数据类型
    变量part2
    JDBC中创建表
  • 原文地址:https://www.cnblogs.com/zjj-php/p/8244288.html
Copyright © 2011-2022 走看看