我有两个表,在两个表中,我都使用 UUID 来生成 id。之后,我尝试在第二个表中使用一个 id 作为外来 ID。如图所示,迁移确实接受我正在做的事情,但是当我插入数据时,我收到此错误
Illuminate/Database/QueryException with message 'SQLSTATE[01000]: Warning: 1265 Data truncated for column 'userId' at row 1
Run Code Online (Sandbox Code Playgroud)
她是我的第一张桌子:
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();
});
Run Code Online (Sandbox Code Playgroud)
第二个带有外键的表
Schema::create('tableTwo', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->unsignedBigInteger('userId');
$table->foreign('userId')
->references('id')
->on('users')
->onDelete('cascade');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)