Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 migrations : default length of different types in Schema::table method

Tags:

mysql

laravel

I'm setting up a migration on Laravel 5 and was wondering if there was some documentation for the default lengths of each of the Column Types ? Do they follow some convention like MySQL's?

Ex: INTEGER, TEXT, MEDIUMTEXT, LONGTEXT

I'm talking about these Column Types : (http://laravel.com/docs/5.0/schema#adding-columns)

like image 611
BassMHL Avatar asked Apr 01 '15 02:04

BassMHL


People also ask

How do I change the default value in Laravel migration?

In our case we are going to do second option - create new migration. If we roll back this migration, we need to remove default value from that field using migration and this is how to do it: Schema::table('photos', function (Blueprint $table) { $table->integer('order')->default(NULL)->change(); });


1 Answers

String types

CHAR - 1 to 191 (trailing spaces removed)

STRING - 1 to 16,300 (user defined)

TEXT - 1 to 65,535

MEDIUMTEXT - 1 to 16,777,215

LONGTEXT - 1 to 4,294,967,295


Integer types

TINYINT - 0 to 255 (unsigned) | -128 to 127 (signed)

SMALLINT - 0 to 65,535 (unsigned) | -32,768 to 32,767 (signed)

MEDIUMINT - 0 to 16,777,215 (unsigned) | -8,388,608 to 8,388,607 (signed)

INT - 0 to 4,294,967,295 (unsigned) | -2,147,483,648 to 2,147,483,647 (signed)

BIGINT - 0 to 18,446,744,073,709,551,615 (unsigned) | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (signed)


Floating types

Structure: `([max decimal places], [max precision])`

FLOAT - ([0-7], [0-23])

DOUBLE - ([0-14], [24-53])

DECIMAL - ([0-65], [0-30])

Note: decimal stores exact value when we print it in INT. See example below:

DOUBLE = DECIMAL = 2.65

//convert it to int

DOUBLE = 2

DECIMAL = 3

See all column type for laravel: documentation

like image 171
Ιησούς του ναυή Avatar answered Oct 19 '22 22:10

Ιησούς του ναυή