N
N
Nightmare0582020-12-15 20:53:55
Laravel
Nightmare058, 2020-12-15 20:53:55

How to create autoincrement field in Laravel without marking primary key?

Good day.
Faced such a situation: I wanted to make 2 fields with autoincrement in the migration so that they change automatically. But it turned out that the autoincrement status implies a primary key. In Google I found a way to fix it through a SQL query.
Maybe there is some other way provided by the developers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
urlportal, 2020-12-19
@urlportal

If you are only creating a field (e.g. unsigned integer)

  1. use second parameter with value true

$table->unsignedInteger('field', true);
If the field has already been created, then some types of fields can be changed (see the docs for specific ones):
  1. describe the field the way you would like it to be
  2. call the change() method at the end

$table->unsignedInteger('id', true)->change();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question