trevorpan's avatar

upgrading from 5.7: unsignedbigInteger and migrations

$table->unsignedInteger('user_id'); to $table->unsignedBigInteger('user_id');

https://laravel.com/docs/5.8/migrations#modifying-columns this has a warning:

Only the following column types can be "changed": bigInteger, binary, boolean, date, dateTime, dateTimeTz, decimal, integer, json, longText, mediumText, smallInteger, string, text, time, unsignedBigInteger, unsignedInteger and unsignedSmallInteger.

so is this how you'd do the above?

    $table->unsignedInteger('user_id', unsignedBigInteger)->change();
});

Will this lose the existing 'user_id' records?

0 likes
2 replies
piljac1's avatar
piljac1
Best Answer
Level 28
$table->unsignedBigInteger('user_id')->change();

As for your second question, I never performed that specific change, but I think that you shouldn't lose any data. Backup your database for safety, and try it.

Side question : why do you want to upgrade to unsignedBigInteger ? You're expecting over 4 billion users ?

trevorpan's avatar

haha, 4B users, that'd be nice!!

It's the first column I grabbed. At the moment, I can't remember which column it was specifically but that integer no longer worked properly, maybe it was a foreign key reference or something like that.

Thank you, just wanted to check with someone about data integrity before I made that change.

Please or to participate in this conversation.