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

Ligonsker's avatar

Why migration integer adds auto_increment and primary key?

I wanted to create some integer columns, but it automatically adds auto_increment and primary key:

$table->integer('some_col');

Why? there already is the $table->id(); at the top

0 likes
9 replies
Ligonsker's avatar

@Sinnbeck when I run php artisan migrate I get error:

SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key (SQL: create table `my_table` (`id` bigint unsigned not null auto_increment primary key, `some_col` int not null auto_increment primary key, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

I only did this:

    public function up()
    {
        Schema::create('data', function (Blueprint $table) {
            $table->id();
            $table->integer('some_col', 50);
            $table->timestamps();
         });
    }
Ligonsker's avatar

@Sinnbeck Oh no, I edited it for this post to make it simpler 😭, it's actually called data

Ligonsker's avatar

@MichalOravec correct

public function integer($column, $autoIncrement = false, $unsigned = false)

From some reason I confused it with VARCHAR

Please or to participate in this conversation.