Skip to content

Schema: mysql error - Multiple primary key defined #7296

@itsa-sh

Description

@itsa-sh

It appears when creating a table the first integer field is considered a primary key and created; The example below will generate a mysql error:

[Illuminate\Database\QueryException]                                         
SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined (SQL: ***)
Schema::create('table_data', function(Blueprint $table)
{
    $table->engine = 'InnoDB';

    $table->integer('record_id', 10)->unsigned();
    $table->double('price', 8, 4);
    $table->date('date');

    $table->primary(['record_id', 'price', 'date']);
});

Where as the following does not throw an exception.

Schema::create('table_data', function(Blueprint $table)
{
    $table->engine = 'InnoDB';

    $table->string('record_id', 10);
    $table->double('price', 8, 4);
    $table->date('date');

    $table->primary(['record_id', 'price', 'date']);
});

EDIT: Also, it appears to create product_id as an AUTO_INCREMENT which is not true either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions