MySQL Laravel 5 迁移:Schema::table 方法中不同类型的默认长度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29381815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:25:20  来源:igfitidea点击:

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

mysqllaravel

提问by BassMHL

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?

我正在 Laravel 5 上设置迁移,想知道是否有一些关于每种列类型的默认长度的文档?他们是否遵循一些像 MySQL 这样的约定?

Ex: INTEGER, TEXT, MEDIUMTEXT, LONGTEXT

例如:整数、文本、中文本、长文本

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

我在谈论这些列类型:(http://laravel.com/docs/5.0/schema#adding-columns

采纳答案by Ymartin

Here is the Laravel documentation link for the column types

这是列类型的 Laravel 文档链接

http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html

http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html

From the documentation, I guess the default of 255 is imposed on string() and char() methods as evident from

从文档中,我猜 255 的默认值是强加给 string() 和 char() 方法的,从

http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html#method_string

http://laravel.com/api/5.0/Illuminate/Database/Schema/Blueprint.html#method_string

Hope this helps!

希望这可以帮助!

回答by Ιησο?? του ναυ?

String types

字符串类型

CHAR- 1 to 191(trailing spaces removed)

CHAR- 1 to 191(删除尾随空格)

STRING- 1 to 16,300(user defined)

STRING- 1 to 16,300(用户定义)

TEXT- 1 to 65,535

文字-1 to 65,535

MEDIUMTEXT- 1 to 16,777,215

中文本-1 to 16,777,215

LONGTEXT- 1 to 4,294,967,295

长文-1 to 4,294,967,295



Integer types

整数类型

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

TINYINT- 0 to 255(未签名) | -128 to 127(签)

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

SMALLINT- 0 to 65,535(无符号) | -32,768 to 32,767(签)

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

MEDIUMINT- 0 to 16,777,215(未签名) | -8,388,608 to 8,388,607(签)

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

INT- 0 to 4,294,967,295(无符号) | -2,147,483,648 to 2,147,483,647(签)

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)

BIGINT- 0 to 18,446,744,073,709,551,615(无符号) | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807(签)



Floating types

浮动类型

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

结构: ([max decimal places], [max precision])

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

浮动-([0-7], [0-23])

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

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

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

十进制-([0-65], [0-30])

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

注意:当我们用 INT 打印时,decimal 存储精确值。请参阅下面的示例:

DOUBLE = DECIMAL = 2.65

//convert it to int

DOUBLE = 2

DECIMAL = 3



查看 laravel 的所有列类型: documentation文件

回答by Kamil Kie?czewski

INTEGERrange 0-4294967295(unsigned) or from -2147483648 to 2147483647(signed) source

INTEGER范围0-4294967295(无符号)或来自-2147483648 to 2147483647(有符号)

TEXTmax size 65,535characters source

TEXT最大大小65,535字符

MEDIUMTEXTmax size 16,777,215characters source

MEDIUMTEXT最大大小16,777,215字符

LONGTEXTmax size 4,294,967,295characters source

LONGTEXT最大大小4,294,967,295字符

More you can find on mysql site which looks like was used by laravel authors.

您可以在 mysql 站点上找到更多看起来像是被 laravel 作者使用的。