public function up(): void
{
Schema::create('media', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->integer('runtime')->nullable();
$table->text('overview')->nullable();
$table->timestamps();
});
Schema::create('lines', function (Blueprint $table) {
$table->foreignId('media_id')->constrained()->cascadeOnDelete();
$table->integer('number');
$table->text('text');
$table->integer('start');
$table->integer('end');
$table->primary(['media_id', 'number']);
});
Schema::create('occurences', function (Blueprint $table) {
$table->id();
$table->foreignId('media_id')->constrained()->cascadeOnDelete();
$table->foreignId('number')->constrained('lines', 'number');
$table->text('base_word');
$table->text('literal');
$table->timestamps();
});
}
Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 3780 Referencing column 'number' and referenced column 'number' in foreign key constraint 'occurences_number_foreign' are incompatible. (Connection: mysql, SQL: alter tableoccurencesadd constraintoccurences_number_foreignforeign key (number) referenceslines(number))
The issue is certainly with this line $table->foreignId('number')->constrained('lines', 'number'); but I am really lost for ideas on how to fix it. Any ideas?