如何使用Laravel Migrations在Mysql列中添加注释

Adn*_*taz 7 php laravel eloquent laravel-5.3

这就是我想要做的

if (!Schema::hasColumn('account_settings', 'minimum_onsite_length')) {
        Schema::table('account_settings', function (Blueprint $table) {
            $table->unsignedInteger('minimum_onsite_length')
                ->default(180)
                ->nullable()
                ->comment('This is comments')
            ;
        });
    }
Run Code Online (Sandbox Code Playgroud)

但是在迁移过程中未显示任何评论,我在这里缺少任何内容吗?

我也看过这个问题,但在这里不起作用

Rah*_*hul 8

你可以这样尝试

if (!Schema::hasColumn('account_settings', 'minimum_onsite_length')) {
    Schema::table('account_settings', function (Blueprint $table) {
        $table->unsignedInteger('minimum_onsite_length')
            ->default(180)
            ->nullable()
            ->comment = 'This is comment';
    });
}
Run Code Online (Sandbox Code Playgroud)

参考链接在这里

  • 根据 Laravel 5.7 的官方文档,可以通过“->comment('my comment')”添加注释。https://laravel.com/docs/5.7/migrations (3认同)
  • 我可以确认 `->comment('my comment')` 在 7.x 之前确实有效。有关官方文档的更多信息 https://laravel.com/docs/7.x/migrations#column-modifiers (2认同)