在 Laravle 6 的数据库迁移中添加表注释

1、在 Laravle 6 的数据库迁移中,数据表选项不支持添加注释。如图1

图1

2、参考:https://stackoverflow.com/questions/37493431/how-to-add-comment-to-table-not-column-in-laravel-5-migration 。How to add comment to table (not column) in Laravel 5 migration? 如图2

图2

3、最终实现如下

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateThemeInstallationTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */    public function up()
    {
        $tableName = 'theme_installation';

        Schema::create($tableName, function (Blueprint $table) {
            $table->increments('id');
            // ...
            $table->timestamps();
        });

        DB::statement('ALTER TABLE ' . DB::connection()->getTablePrefix() . $tableName . ' COMMENT \'主题安装\'');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */    public function down()
    {
        Schema::dropIfExists('theme_installation');
    }
}

4、执行数据库迁移后,查看执行结果,表注释已经实现。如图3

图3

永夜