Laravel 5.5 设置迁移文件中整数字段的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47987923/
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-09-08 17:51:40  来源:igfitidea点击:

Laravel 5.5 set size of integer fields in migration file

laravellaravel-5.5

提问by Hax0r

I am new to laravel.

我是laravel的新手。

Now i am using the migrate command to make a table, but the length of the filed is not applicable. Laravel does not provide this option. ?

现在我正在使用 migrate 命令来制作一个表格,但该字段的长度不适用。Laravel 没有提供这个选项。?

Below is my codes:

下面是我的代码:

$table->increments('id')->length(11);
$table->dateTime('created_time');
$table->integer('bank_id')->length(11);
$table->tinyInteger('is_black')->length(1);

The length of the field is_blackshould be 1, but it is actually being generated as 4. How can I solve this problem ?

字段的长度is_black应该是 1,但它实际上被生成为 4。我该如何解决这个问题?

Any suggestion or advice would be appreciated.

任何建议或建议将不胜感激。

Thank you in advance

先感谢您

回答by Alexey Mezenin

You can't do this, but you can use different types of integer:

你不能这样做,但你可以使用不同类型的整数:

$table->bigInteger()
$table->mediumInteger()
$table->integer()
$table->smallInteger()
$table->tinyInteger()

https://laravel.com/docs/5.5/migrations#columns

https://laravel.com/docs/5.5/migrations#columns

回答by user12255561

$table->increments('id',11);
$table->dateTime('created_time');
$table->integer('bank_id',11);
$table->tinyInteger('is_black',1);

回答by mfadel

According to https://laravel.com/docs/5.5/migrations, you can use one of these types:

根据https://laravel.com/docs/5.5/migrations,您可以使用以下类型之一:

$table->bigInteger('votes');
$table->integer('votes');

$table->mediumInteger('votes'); 
$table->smallInteger('votes');
$table->tinyInteger('votes');
$table->unsignedBigInteger('votes');
$table->unsignedMediumInteger('votes'); 
$table->unsignedSmallInteger('votes');  
$table->unsignedTinyInteger('votes');   

回答by quoctinh0897

You can use this way. Good luck.

您可以使用这种方式。祝你好运。

$table->decimal('is_black',1,0);

$table->decimal('is_black',1,0);

回答by oriberu

According to https://laravel.com/docs/5.1/migrations, as of Laravel 5.1 you can use the booleancolumn type to create a "boolean-like" TINYINTof length 1 (MySQL). So, for example:

根据https://laravel.com/docs/5.1/migrations,从 Laravel 5.1 开始,您可以使用boolean列类型创建TINYINT长度为 1 (MySQL)的“类布尔值” 。因此,例如:

$table->boolean('nameOfColumn');