用了很久的 Laravel,在制作迁移的时候,我一直以为给表添加注释是这样的
用 $this->comment
给表添加注释
<?php Schema::create('wallets', function (Blueprint $table) { $table->comment = '钱包'; $table->increments('id'); $table->unsignedInteger('user_id')->comment('所属用户'); $table->string('coin', 16)->comment('币种'); $table->decimal('balance_available', 20, 8)->default(0)->comment('可用余额'); $table->decimal('balance_locked', 20, 8)->default(0)->comment('冻结资产'); $table->timestamps(); $table->unique([ 'user_id', 'coin' ]); });
然后发现这是错的,错的,根本不起作用,正确的用法是
\DB::statement("ALTER TABLE `wallets` comment '钱包'");
范例
public function up() { Schema::create('wallets', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('user_id')->comment('所属用户'); $table->string('coin', 16)->comment('币种'); $table->decimal('balance_available', 20, 8)->default(0)->comment('可用余额'); $table->decimal('balance_locked', 20, 8)->default(0)->comment('冻结资产'); $table->timestamps(); $table->unique([ 'user_id', 'coin' ]); }); \DB::statement("ALTER TABLE `wallets` comment '钱包'"); }
目前尚无回复