Search code examples
phplaravelartisan-migrate

SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition;


Migration File

$table->increments('id');
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('band_id')->references('id')->on('bands');
$table->foreign('genre_id')->references('id')->on('genres');
$table->foreign('cate_id')->references('id')->on('cates');
$table->foreign('type_id')->references('id')->on('types');
$table->integer('status');
$table->date('date');
$table->time('time');
$table->decimal('price');
$table->tinyIncrements('instrument');
$table->string('instrument_detail',255);
$table->timestamps();

After run 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 bookings (id int unsigned not null auto_increment primary key, status int not null, date date not null, time time not null, price decimal(8, 2) not null, instrument tinyint unsigned not null auto_increment primary key, instrument_detail varchar(255) not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)

And this below

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


Solution

  • $table->unsignedTinyInteger('instrument', true);
    

    2nd parameter is bool for auto increment default to false