Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahr's avatar
Level 10

Multiple primary key defined

What is this error/

error

migration

    Schema::create('language_user', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('language_id')->unsigned();
        $table->foreign('language_id')->references('id')->on('languages')->onDelete('cascade');
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->primary(['language_id' , 'user_id']);
        $table->integer('reading_skill');
        $table->integer('writing_skill');
        $table->integer('listening_skill');
        $table->timestamps();
    });
0 likes
7 replies
Snapey's avatar

As it says, you are trying to add a primary key when your table already contains one.

1 like
MichalOravec's avatar
Level 75

You can't have two primary keys in one table.

Change this

$table->primary(['language_id' , 'user_id']);

to

$table->unique(['language_id' , 'user_id']);

If they have to be unique.

bigIncrements and primary both of them create a primary key.

4 likes
automica's avatar

@oxbir then you still have an issue with your primary keys.

Can you post your most up to date migration

1 like

Please or to participate in this conversation.