Waqar Fazal
Waqar Fazal

Reputation: 11

how to add auto-increments on non primary key column, but their is still another column which i want to set as primary key

i'm creating a database for school management in laravel.. i'm stuck in students table where i want to set primary key as "reg_no" column without auto-incrementing and still want the "id" column as auto-incrementing, i tried "protected $primaryKey" and "public $incrementing" but these properties does not solve the problem..

after did this, my db still point "id" column as primary key..

Here are some screen shots:

model:

image

table/migration:

image

Database in Xampp:

image

Upvotes: 0

Views: 497

Answers (1)

syam
syam

Reputation: 892

Add this in 'up' method of students migration file

Schema::table('students', function(Blueprint $table) {

    // Remove the primary key
    $table->dropPrimary("id");

    // Set the actual primary key
    $table->primary(array("reg_no"));
});

Upvotes: 0

Related Questions