Spe*_*ark 12 database-schema laravel-4
我一直在四处寻找,问了几次问题,但似乎没有人能给出明确的答案.如何使用Schema指定表列的整数长度?
我见过有人建议:
$table->integer('post')->length(11);
Run Code Online (Sandbox Code Playgroud)
但这不起作用 - 至少在Laravel 4.2中 - 它仍然会产生列int(10).
是否有内置方法来指定整数长度?
low*_*nds 17
如果您使用的是MySQL,则无法指定整数列的长度.您只能在http://dev.mysql.com/doc/refman/5.1/en/integer-types.html中描述的可用整数类型之间进行选择.
因此,您也无法在Laravel中设置整数长度.您只能选择http://laravel.com/docs/schema#adding-columns中描述的其中一种可用类型.
Gra*_*ant 10
以为我会为一般情况表创建一个易于复制和粘贴的表。
如果你签名也需要负的值,如果无符号没有。
| 类型 | Eloquent (Schema Builder) | 敏| 最大 |
| ------------------- | ----------------------------------------- | ------- | ------ |
| TINYINT(签名) | $table->signedTinyInteger('foo') | -128 | 127 |
| TINYINT(无符号) | $table->unsignedTinyInteger('foo') | 0 | 第255话
| SMALLINT(签名) | $table->signedSmallInteger('foo') | -32768 | 32767 |
| SMALLINT(无符号) | $table->unsignedSmallInteger('foo') | 0 | 65535 |
对于更大的整数类型,请参阅:https : //dev.mysql.com/doc/refman/5.5/en/integer-types.html
| 归档时间: |
|
| 查看次数: |
21939 次 |
| 最近记录: |