我有两个表,在这两个表中,我都使用 UUID 生成一个 ID。然后,我试图在第二个表中将一个 ID 用作外键。如下所示:迁移确实接受了我的操作,但是当我插入数据时,却出现了以下错误。
Illuminate/Database/QueryException with message 'SQLSTATE[01000]: Warning: 1265 Data truncated for column 'userId' at row 1
这是我的第一张表格:
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('userName')->unique();
$table->string('email')->unique();
$table->boolean('isVerified')->default(false);
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
带有外键的第二个表
Schema::create('tableTwo', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->unsignedBigInteger('userId');
$table->foreign('userId')
->references('id')
->on('users')
->onDelete('cascade');
$table->timestamps();
});