Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel migration boolean field created in Db like tiny integer

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?

like image 426
Stefano Maglione Avatar asked May 17 '17 15:05

Stefano Maglione


People also ask

How do I change the field type in Laravel migration?

open your migration file and write down below. Schema::table('yourTable', function (Blueprint $table) { $table->string('column_name','4294967295')->change(); }); As, longText have maximum of 4,294,967,295 character limit, Laravel will automatically change column_name to longText data type.

How do I change the default value in Laravel migration?

You can use change() method: Schema::table('users', function ($table) { $table->integer('active')->default(0)->change(); }); We were able to comprehend how to correct the Laravel Migration Change Default Value issue thanks to the many examples.

What is nullable in Laravel?

It will make the column nullable in the database which means you can store null values to that column or also can be said that it is not a mandatory field in database.


1 Answers

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

like image 194
Rezrazi Avatar answered Sep 30 '22 21:09

Rezrazi