How to define a non-incremental primary key in Laravel 5?


A query. I have the table clients with the id and name fields.

By means of a barcode reader I read a card, and I want to save the number that has said card (ex: 123465) in the id field, and that this field is my primary key.

Laravel, saves by default the id as incremental, however if I take the incremental option and put integer , when doing migrate , it does not keep the id as primary key.

What I need is to create the id field, but that it is a primary key and in turn is not incremental.

asked by Pablo Rivera Madrazo 16.03.2017 в 17:16

1 answer


The solution is to declare the field as you normally do, but add the index by means of:

Schema::table('users', function($table)

as the documentation shows Adding indexes

answered by 16.03.2017 / 17:19