Home > Blockchain >  Incorrect table definition; there can be only one auto column
Incorrect table definition; there can be only one auto column

Time:07-17

Migration File

public function up()
{
    Schema::create('progress', function (Blueprint $table) {
        $table->id();
        $table->foreignId('state_id')->constrained()->cascadeOnDelete();
        $table->foreignId('city_id')->constrained()->cascadeOnDelete();
        $table->text('address');
        $table->string('project_name');
        $table->tinyInteger('status', 2);
        $table->timestamps();
    });
}

After running php artisan migrate

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 progress (id bigint unsigned not null auto_increment primary key, state_id bigint unsigned not null, city_id bigint unsigned not null, address text not null, project_name varchar(255) not null, status tinyint not null auto_increment primary key, created_a t timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

CodePudding user response:

Your migration has defined the tiny integer column as an auto increment column. Take a look at the Laravel tinyInterger docs and you’ll see the second argument is a Boolean for defining the column as auto increment.

So to remove this error you’ll need to remove the 2 from your column definition.

  • Related