1

Hello I am currently trying to set up a migration in Laravel and am running into the issue to that all of my numeric columns are being set to autoincrement.

Test Migration:

Schema::create('sublobbies', function (Blueprint $table) {
    $table->increments('id');
    $table->tinyInteger('sub', 2)->default(1);
    $table->tinyInteger('anothertable', 2)->default(1);
    $table->tinyInteger('anothertable2', 2)->default(1);
});

Besides the fact, that I am getting an Invalid default value error (im assuming due to the auto increments), I noticed that everything is being set to auto increment:

Syntax error or access violation: 1067 Invalid default val  
  ue for 'sub' (SQL: create table `sublobbies` (`id` int unsigned not null au  
  to_increment primary key, `sub` tinyint not null default '1' auto_increment  
   primary key, `anothertable` tinyint not null default '1' auto_increment pr  
  imary key, `anothertable2` tinyint not null default '1' auto_increment prim  
  ary key) default character set utf8mb4 collate utf8mb4_unicode_ci) 

Is this the natural behavior of Migrations or am I just missing something? How do I turn auto_increment off?

Shawn31313
  • 5,978
  • 4
  • 38
  • 80

1 Answers1

6
Schema::create('sublobbies', function (Blueprint $table) {
    $table->increments('id');
    $table->tinyInteger('sub', 2)->default(1); // remove the , 2
    $table->tinyInteger('anothertable', 2)->default(1); // remove the , 2
    $table->tinyInteger('anothertable2', 2)->default(1); // remove the , 2
});

the second spot in the tinyInteger() function is a boolean you are setting to true should just be

Schema::create('sublobbies', function (Blueprint $table) {
    $table->increments('id');
    $table->tinyInteger('sub')->default(1);
    $table->tinyInteger('anothertable')->default(1); 
    $table->tinyInteger('anothertable2')->default(1);
});

Adding this for reference:

tinyInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)

https://laravel.com/api/4.2/Illuminate/Database/Schema/Blueprint.html#method_tinyInteger

cre8
  • 13,012
  • 8
  • 37
  • 61
Asheliahut
  • 901
  • 6
  • 11