Laravel 5.5 set size of integer fields in migration file
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
When using Laravel to create tables with migrations, it is essential to understand how to control the size of various field types. While Laravel does not provide direct options for setting field lengths within migrations, there are workarounds and best practices that can be followed to ensure proper length specifications.
Working with Integer Fields
In your example code snippet, you have the following migration:php
$table->increments('id')->length(11);
$table->integer('bank_id')->length(11);php
class YourModel extends Model {
/**
* Get the primary key type.
*/
public function getPrimaryKeyType()
{
return 'integer'; // Default is 'bigInteger'
}
}php
$table->smallInteger('bank_id');
$table->tinyInteger('is_black');php
class YourModel extends Model {
/**
* Get the primary key type.
*/
public function getPrimaryKeyType()
{
return 'tinyInteger'; // Default is 'bigInteger'
}
}Possible Pitfalls and Alternative Solutions
Setting custom field lengths in your model classes should generally be avoided, as it may cause compatibility issues with later Laravel versions. A better approach would be to set the appropriate field types that support custom lengths during migration creation. For instance:php
$table->tinyInteger('is_black');