Error: Illuminate\Database\QueryException SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined (SQL: alter table
mediablesadd primary keymediables_media_id_mediable_type_mediable_id_tag_primary(media_id,mediable_type,mediable_id,tag))
my migration :
if (!Schema::hasTable('media')) {
Schema::create(
'media',
function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('disk', 32);
$table->string('directory');
$table->string('filename');
$table->string('mime_type');
$table->string('aggregate_type');
$table->string('extension', 32);
$table->integer('size')->nullable(false);
$table->timestamps();
$table->unique(['disk', 'directory', 'filename', 'extension']);
}
);
}
if (!Schema::hasTable('mediables')) {
Schema::create(
'mediables',
function (Blueprint $table) {
$table->increments('media_id');
$table->string('mediable_type');
$table->integer('mediable_id')->unsigned();
$table->string('tag');
$table->integer('order')->unsigned();
$table->primary(['media_id', 'mediable_type', 'mediable_id', 'tag']);
$table->index(['mediable_id', 'mediable_type']);
$table->index('tag');
$table->index('order');
$table->foreign('media_id')
->references('id')->on('media')
->cascadeOnDelete();
}
);
}
You cant use
incrementsfor foreign_key. UseunsignedBigIntgerinstead: