7

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?

Blip
  • 3,061
  • 5
  • 22
  • 50
Stefano Maglione
  • 3,946
  • 11
  • 49
  • 96
  • You can visit below link for more clarity: https://stackoverflow.com/questions/11167793/boolean-or-tinyint-confusion – bishop Dec 24 '18 at 16:00

1 Answers1

14

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

Brane
  • 3,257
  • 2
  • 42
  • 53
Rezrazi
  • 865
  • 1
  • 7
  • 18
  • This question is not related to mysql. It is related to laravel migration – Blip Dec 17 '18 at 10:57
  • 2
    Also there is problem that TINYINT(1) doesn't have a size of `1 bit` but `1 byte`! Only `BIT(1)` have really size of a `1 bit` – tomas.lang Jun 07 '19 at 13:44
  • Isn't it not even 1 byte? But something like "in case you export it to a mainframe compatible format, this will be printed as 1 character". E.g. trimmed to the last decimal character: 0 to 9. You won't see that during normal queries. – Henk Poley Sep 10 '20 at 12:51