Your users table has an id column?
Why do you need to specify the key name?
Hi, I’m encountering an issue with a migration that creates a tickets table, which has a one-to-many relationship with the users table. Normally, the tickets table should include a foreign key referencing the users table. However, when I try to define it using: $table->foreignId('user_id')->constrained(indexName: 'FK_USER_TICKETS')->onDelete('cascade'); it only creates the user_id column without actually generating the foreign key constraint in the database, even though I expected it to.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('tickets', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained(indexName: 'FK_USER_TICKETS')->onDelete('cascade');
$table->string('title' , 40);
$table->text('description');
$table->string('status');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('tickets');
}
};
Please or to participate in this conversation.