如何使用 Laravel Schema Builder 在表上设置注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34271843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:48:56  来源:igfitidea点击:

How to set a comment on table using Laravel Schema Builder

laravelcommentsschema

提问by Andris Briedis

How to set a comment on table using Laravel Schema Builder?

如何使用 Laravel Schema Builder 在表上设置评论?

Column set:

列集:

public function up()
{
    Schema::create('vendors', function (Blueprint $table) 
    {
        $table->comment('not working - error'); // not working - error
        $table->increments('id');
        $table->string('vendor', 255)->comment('Some comment.');
        $table->timestamps();
    });
}

But for the table?

但是对于桌子?

回答by Fabio Antunes

Well I don't have a nice answer for you, but at least it works.

好吧,我没有给你一个很好的答案,但至少它有效。

Here it is:

这里是:

public function up()
{
    $tableName = 'vendors';

    Schema::create($tableName, function (Blueprint $table) 
    {
        $table->increments('id');
        $table->string('vendor', 255)->comment('Some comment.');
        $table->timestamps();
    });

    DB::statement("ALTER TABLE `$tableName` comment 'My comment'");
}

Just add a DB statement after creating your table.

只需在创建表后添加一条 DB 语句即可。