Laravel 5.5 sets the size of integer fields in a migration file

I am new to laravel.

Now I use the migrate command to create the table, but the field length is not applicable. Laravel does not provide this option.

Below are my codes:

$table->increments('id')->length(11);
$table->dateTime('created_time');
$table->integer('bank_id')->length(11);
$table->tinyInteger('is_black')->length(1);

The field length is_blackshould be 1, but it is actually generated as 4. How can I solve this problem?

Any suggestion or advice would be appreciated.

Thank you in advance

+8
source share
5 answers

You cannot do this, but you can use various types of integers:

$table->bigInteger()
$table->mediumInteger()
$table->integer()
$table->smallInteger()
$table->tinyInteger()

https://laravel.com/docs/5.5/migrations#columns

+12
source

According to https://laravel.com/docs/5.5/migrations , you can use one of the following types:

$table->bigInteger('votes');
$table->integer('votes');

$table->mediumInteger('votes'); 
$table->smallInteger('votes');
$table->tinyInteger('votes');
$table->unsignedBigInteger('votes');
$table->unsignedMediumInteger('votes'); 
$table->unsignedSmallInteger('votes');  
$table->unsignedTinyInteger('votes');   
+3

. .

$table->decimal('is_black',1,0);

+1

According to https://laravel.com/docs/5.1/migrations , starting with Laravel 5.1, you can use the column type booleanto create a "logical" TINYINTlength of 1 (MySQL). For example:

$table->boolean('nameOfColumn');
+1
source
$table->increments('id',11);
$table->dateTime('created_time');
$table->integer('bank_id',11);
$table->tinyInteger('is_black',1);
0
source

Source: https://habr.com/ru/post/1691395/


All Articles