Skip to content
Advertisement

Laravel 9: Numeric value out of range: 1264 Out of range value for column ERROR

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?

Advertisement

Answer

It’s because integer has a maximum range of 2147483647 and minimum -2147483648 if it is signed (- / +) and maximum of 4294967295 and minimum of 0 when 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 a varchar or $table->string() in laravel is a good idea.

Integer Types (Exact Value) – INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement