Laravel migration boolean field created in Db like tiny integer

Stefano Maglione picture Stefano Maglione · May 17, 2017 · Viewed 13.7k times · Source

I wrote a migration in Laravel:

 Schema::create('test', function (Blueprint $table) {
        //
        $table->increments('id');
        $table->string('city','30')->unique();
        $table->string('car','30')->unique();
        $table->boolean('required');
        $table->string('street','100')->nullable();
        $table->json('files');
        $table->timestamp('created_at');
    });

the field required is defined as boolean but in the db (MySql) is created as tinyint. How is it possible?

Answer

Rezrazi picture Rezrazi · May 17, 2017

Tinyint is the same as boolean. Tinyint is an integer of size equal to 1 octet. When creating the column set as boolean the the db creates it as a tinyint with a size of 1 bit. Thus making it's possible values 0and 1 which is a boolean.


From MySQL documentation

BOOL, BOOLEAN

These types are synonyms for TINYINT(1). A value of zero is considered false. Nonzero values are considered true

Numeric Type Overview