【发布时间】:2026-01-23 00:45:01
【问题描述】:
我有以下迁移:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UpdateRatingGameUserAnswersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('rating_games_user_answers', function (Blueprint $table) {
$table->uuid('answer_token')->default(DB::raw('UUID()'));
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('rating_games_user_answers', function (Blueprint $table) {
$table->dropColumn('answer_token');
});
}
}
如您所见,我正在尝试将 UUID 设置为默认值。我看过here
但是当我运行php artisan migrate 时,我看到以下内容:
怎么了?
【问题讨论】:
-
UUID() 是 MySQL 中的触发器吗?
-
我记得。 UUID() 是 mysql 中的默认函数。见这里mysqlserverteam.com/storing-uuid-values-in-mysql-tables 例如,请求
SELECT UUID()给了我uuid。