I'm working with Laravel 9 and I have used this column at users table for storing user mobile phone number:
$table->integer('usr_mobile_phone');
And at the factor, I tried this to fill out this column:
public function definition()
{
$fs = '091';
$ch = '1234567890';
$str = $fs.str_shuffle($ch);
return [
'usr_mobile_phone' => $str
...
];
}
But when I run php artisan db:seed, I get this error:
SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'usr_mobile_phone' at row 1
So what's going wrong here?
How can I store the number properly at the user's mobile phone number column in the DB?
It's because
integerhas a maximum range of2147483647and minimum-2147483648if it is signed (- / +) and maximum of4294967295and minimum of0when it is not. So inserting a phone number that usually has a 11 digits exceed its maximum value and depends on how your number is formatted like @Amjad said you cannot put a string in an integer column so using avarcharor$table->string()in laravel is a good idea.Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT