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

 


免責聲明!

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



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